Skip to content
Prev 177506 / 398503 Next

Loop question

On Fri, Apr 17, 2009 at 10:12 PM, Brendan Morse <morse.brendan at gmail.com> wrote:
Very close.  But since you've started out with a *matrix* t1, your
assignments to t1[i] will assign to parts of the matrix.  To correct
this, all you need to do is initialize t1 as a *list of matrices* or
(even better) as an *empty list*, like this:

   t1 <- list()

and then assign to *elements* of the list (using [[ ]] notation), not
to *sublists* of the list (which is what [ ] notation means in R),
like this:

for(i in 1:10){
       t1[[i]] <- rnorm(250)
}

Is that what you had in mind?

           -s