[R] Appending intermediate terms in a For Loop

Jason.L.Higbee@stls.frb.org
Mon, 15 Dec 2003 19:47:23 -0000

R UseRs:

I can't figure out how to append intermediate terms inside a For loop.  My
use of append(), various indexing, and use of data frames, vectors,
matrices has been fruitless.  Here's a simplified example of what I'm
talking about:

i <- 1
for(i in 10) {
    v[i] <- i/10
}
> v
 [1]  1 NA NA NA NA NA NA NA NA  1

I would like: [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Any help on this would be greatly appreciated.

-Jason

PS:  I realize that I could have gone v <- 1:10, then v <- v / 10, as I
said this is a simplified example; the actual function to be evaluated
iteratively in the for loop is more complex than just "x /10"
	[[alternative HTML version deleted]]