[R] creating list with 200 identical objects

Romain Francois romain.francois at dbmail.com
Mon Jun 1 12:19:20 CEST 2009


Hi,

Here are a few ways:

rep( list( new("track") ), 5 )
lapply( 1:5, function(x) new("track") )
list( new("track") ) [ rep(1, 5 ) ]

Romain

Rainer M Krug wrote:
> Hi
>
> I am doing an simulation, and I a large proportion of the simulation
> time is taken up by memory allocations.
>
> I am creating an object, and storing it in a list of those objects.
>
> essentially:
>
> x <- list()
> for (t in 1:500) {
>  x[1] <- new("track")
> }
>
> I would like to initialize in one go, to avoid the continuous
> reallocation of memory when a new "track" is added, and fill it wit
> the object created by new("track").
>
> How can I do this?
>
> thanks
>
> Rainer
>   


-- 
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr




More information about the R-help mailing list