[R] creating a list of matrices or data frames

hadley wickham h.wickham at gmail.com
Tue Jan 20 19:36:07 CET 2009


On Tue, Jan 20, 2009 at 10:34 AM, Simon Pickett <simon.pickett at bto.org> wrote:
> Hi all,
>
> How would you create a list of data.frames within a loop, then bind all the
> elements of the list using rbind?
>
> take this example of matrices with differing numbers of rows
>
> for(i in 1:3){
> assign(paste("s",i, sep=""),matrix(data = NA, nrow = i, ncol = 3, byrow =
> FALSE, dimnames = NULL))
> }
> s1
> s2
> s3
>
> I want to bind all the matrices at the end with do.call(rbind...)  rather
> than listing all the elements manually with rbind(s1,s2,s3...) and so on.

You might also want to have a look at the plyr package,
http://had.co.nz/plyr, which provides general tools for performing
these sorts of operations.

Hadley


-- 
http://had.co.nz/




More information about the R-help mailing list