[R] Initializing lists with n objects

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri May 11 18:03:07 CEST 2007


On Fri, 11 May 2007, Sam Field 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()).

And with lists equally easy via vector("list", n), which is mentioned on 
the help page for list.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list