Skip to content
Prev 76014 / 398502 Next

priority of operators in the FOR ( ) statement

Since there is nothing wrong with

for(i in 1:nr - 1)

R can't really do much more than point to where your code
fails due your incorrect assumption about operator precedence.
You're certainly not the first to fall into this trap. But it's
not that hard to diagnose. Anytime I have problems with a loop,
I do three simple things:

1. for(i in whatever) print(i)
2. look at what traceback() says
3. step through the loop "by hand".

The first test would have told you (in much less than an
"entire evening") what the problem was.


Peter Ehlers
Ravi.Vishnu at outokumpu.com wrote: