missing value true / false: error in loop not in one-off
- by vincent hay
I am new on R and I have a problem with a test in a loop that I want to code. With a data frame (tabetest) like the one here after:
Date 25179M103
1 14977 77.7309
2 14978 77.2567
3 14979 77.7507
I have:
if(tabetest[3,"Date"]-tabetest[1,"Date"]1){print("ok")}
[1] "ok"
But:
j=1
> position = 1
> price=tabetest
for (i in 1:nrow(tabetest)-position){if(tabetest[i+position,"Date"]-tabetest[position,"Date"]>20){price[i+position,j]=price[i+position,j]/price[position,j]-1};position=position+1}
Returns an error. R says that there is a missing value where true/false is required in:
if (tabetest[i + position, "Date"] - tabetest[position, "Date"] >
I have spent quite some time on that error but still don't understand where it comes from.
Thanks for your help,
Vincent