Skip to content
Prev 294938 / 398502 Next

Problem when index is given by a changing formula in loop - BUG??

No it's not a bug in R.

Indexing can only occur by integers so there's an automatic conversion
to integer inside of `[`. Your "insert" variable is actually slightly
less than 8 (note as.integer(insert) == 7) by some amount that's too
small to print, but the computer still picks up on.

More concretely:

x <- 1:10

x[2]
x[3]
x[2.2]
x[2.8]
x[2.999999]

x[insert]
x[as.integer(insert)]
x[round(insert)]

Hopefully that helps clear things up,

Michael

On Fri, May 18, 2012 at 7:50 AM, greatest.possible.newbie
<daniel.hoop at gmx.net> wrote: