[R] rbind-ing list

Patrick Burns pburns at pburns.seanet.com
Tue Jan 30 11:41:12 CET 2007


The original poster is correct that the loop can be
astoundingly inefficient.  The issue is not so much
overwriting a variable, but increasing its size as it
is overwritten.

In cases where 'do.call' won't do, then a good approach
is to create the object with its final size and then
subscript into it to replace parts of it on each iteration.

Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

jim holtman wrote:

>do.call(rbind, temp)
>
>On 1/29/07, jiho.han <jiho.han at yahoo.com> wrote:
>  
>
>>hi,
>>
>>i have a list of data.frame that has same structure. i would like to know a
>>efficient way of rbind-ing it.
>>right now, i write:
>>
>>
>>n = length(temp)     # 'temp' is a list of data.frames
>>temp2 = data.frame()
>>for (i in 1:n) temp2 = rbind( temp2, temp[[i]])
>>return(temp2)
>>
>>
>>but this is not an efficient way since we keeping overwriting temp2. i
>>wonder if there's faster way.
>>
>>thanks
>>--
>>View this message in context: http://www.nabble.com/rbind-ing-list-tf3140137.html#a8703373
>>Sent from the R help mailing list archive at Nabble.com.
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>and provide commented, minimal, self-contained, reproducible code.
>>
>>    
>>
>
>
>  
>



More information about the R-help mailing list