[R] R loops

cvandy cvandy26 at gmail.com
Mon Jan 28 14:48:04 CET 2008


I'm a new user and am having trouble with loops.
In the following, I'm trying to add the results of "test" and the loops are
not working.
I've simplified the loop.  What am I doing wrong?
Thanks!
> test<-numeric(20)
> tot<-numeric(20)
> for(i in 1:20){test[i]<-1}
> for (i in 1:20){tot[i]<-(test[i]+tot[i])}
> tot
 [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

-- 
View this message in context: http://www.nabble.com/R-loops-tp15135671p15135671.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list