missing value true / false: error in loop not in one-off

Posted by vincent hay on Stack Overflow See other posts from Stack Overflow or by vincent hay
Published on 2012-06-17T21:12:41Z Indexed on 2012/06/17 21:16 UTC
Read the original article Hit count: 372

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about r

    Related posts about testing