Re: [R] Flattening a list of data frames

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.ac.be>
Date: Thu 10 Mar 2005 - 20:14:55 EST

try this:

do.call("rbind", z)

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


> Hello all,
>
> Simple version of my problem:
>
> I've got a list of data frames, where each data frame has the same
> number of columns and the same column names. I'd like to flatten the
> list into one large data frame. Is there an easy way to do this?
>
> Quick example code:
> a <- data.frame(x=c(1,2,3),y=c(5,7,9)
> b <- data.frame(x=c(2,4,7,9),y=c(2,3,5,4))

> z <- list(a,b)
>
> # Do "something" to get the equivalent of rbind(z[[1]],z[[2]])
> ???
>
> More complex version:
>
> My data is in this format because it's the output of a "by" statment
> that looks like this:
>
> y <- by(d,list(d$StudentID,d$Assignment),gapfun)
>
> (where gapfun is a function I've defined that takes a data frame and
> returns another data frame).
>
> What I would like is to do is transform y into a data frame that has
> columns "StudentID", "Assignment", and the columns in the data frame
> returned by gapfun.
>
> Any ideas?
>
> Lorin
>
> ----------
> Lorin Hochstein
> Graduate Research Assistant
> Experimental Software Engineering Group
> Computer Science Department
> University of Maryland, College Park
>
> ______________________________________________
> R-help@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
>



R-help@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 Received on Thu Mar 10 20:22:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:42 EST