Skip to content
Prev 258281 / 398502 Next

Odp: for loop with global variables

Hi

r-help-bounces at r-project.org napsal dne 28.04.2011 16:16:16:
Don't do that. As Jim suggested use list inside a loop.

#declare a list
lll<-vector("list",3)

#do your loop
for(i in 1:3) lll[[i]] <- letters[i]

lll
[[1]]
[1] "a"

[[2]]
[1] "b"

[[3]]
[1] "c"

But I feel that you could maybe achieve desired result without loop in 
more Rish way. If what you want to do is reasonable and frequent I believe 
somebody already made a function which does what you want.

Regards
Petr
http://www.R-project.org/posting-guide.html