I'm trying to write a loop in R that finds and marks points in the set where the change in frequency is greater than a certain percentage. Heres's my code
change = c(1:length(df3$frequency)-1)
hold = c(1:length(df3$frequency))
for(i in 1:length(df3$frequency)-1){
hold[i] = (df3$frequency[i+1] - df3$frequency[i])/df3$frequency[i]
if(hold[i] < 0.004){
change[i] = 'True'
}
}
Error in if (hold[i] < 0.004) { : argument is of length zero
I've tried changing the percentage amount, and also changing the vector types. However I cannot understand the issue with the if statement.