[R] Converting "list of data frame" to data frame
John Kane
jrkrideau at yahoo.ca
Mon Apr 30 02:42:45 CEST 2007
I just tried an artifical example and the approach
seems to work okay
# Joining data.frames stored in a list
# From "Douglas Bates"
aa <- 1:4
bb <- 2:5
cc <- 3:6
dd <- 4:7
ee <- 5:8
ff <- c(rep(NA,4))
gg <- 6:9
lst <- list(data.frame(aa,bb), data.frame(cc,dd),
data.frame(ee,ff,gg))
tatiana <- names(lst) <- c("A", "C", "E")
maxy <- do.call("rbind", c(lst$A, lst$C, lst$E)) ;
maxy
miny <- do.call("cbind", c(lst$A, lst$C, lst$E)) ;
miny
What are the dimensions of your data frames?
--- Ajit Pawar <ajitpawar75 at gmail.com> wrote:
> Douglas/R-help,
> Thanks for your reply. I did try the
> solution but the result is not
> what I expect and I also get the following warning
> message:
>
> -------------------
> Warning message:
> number of columns of result
> is not a multiple of vector length (arg 1)
> in: rbind(1, c(6, 9, 10,
> 12, 13, 14, 19, 22, 29, 30, 42, 45, 47,
> -------------------
>
> The "list of data frames" that sapply
> returns has same number of
> columns *but* different number of rows depending on
> the index of sapply.
>
> Any idea what might be going wrong?
>
> Many thanks in advance!.
>
> Cheers
>
> AP
>
>
>
>
>
>
> On 4/29/07, Douglas Bates <bates at stat.wisc.edu>
> wrote:
> >
> > On 4/28/07, Ajit Pawar <ajitpawar75 at gmail.com>
> wrote:
> > > Greetings,
> > > This might be something very simple but a
> nice solution eludes
> > me!!
> > >
> > > I have a function that I call within
> sapply that generates data
> > frame
> > > in each call. Now when sapply returns me back
> the result - it's in the
> > form
> > > of a "list of data frames". so in order to
> extract the information into
> > a
> > > single data frame I have to loop thru the
> following code:
> > >
> > > for(i=1:n) {
> > > my.df =
> rbind(my.df,list.from.sapply[,i]);
> > > }
> > >
> > > Is there anyway to code it better?
> >
> > do.call("rbind", my.df.list.from.sapply)
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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