[R] Initializing lists with n objects

John Kane jrkrideau at yahoo.ca
Fri May 11 18:23:00 CEST 2007


mylist <-  as.list (matrix(1:5))  

might work. Note the elements of the list  are not
empty
--- Sam Field <fieldsh at mail.med.upenn.edu> wrote:

> Hopefully quick question.   I would like to populate
> a list with n 
> objects using a for loop, so within the loop (i to
> n)  I need to refer 
> to a list as example.list[[i]] .  This requires that
> I create a 
> example.list[[i]] with n objects before the for
> loop.  How do I do 
> this?   With matrices it is easy (matrix()). 
> 
> thanks!
> 
> Sam



More information about the R-help mailing list