[R] For the record: how to merge data frames vertically

Prof Brian D Ripley ripley at stats.ox.ac.uk
Thu Mar 9 10:15:05 CET 2000

On Thu, 9 Mar 2000, Kaspar Pflugshaupt wrote:

> Hello,
> to save searching time in the S-news archive, here is the simple solution to
> merge data frames vertically (cols must be equivalent, of course). The

To avoid confusion, that is not the usual meaning of `merge', but
of concatenate, say.

> frames must be components of a list, such as produced by
> framelist<-split(bigframe,factor).
> bigframe2<-do.call("rbind",framelist)
> # posted to S-news by Bill Venables, found in summary message
> http://lib.stat.cmu.edu/s-news/Burst/13564
> The result is identical to bigframe with the exception of the rownames.
> Those seem to be generated by pasting the respective component name and each
> rowname (maybe to prevent non-unique rownames?). To keep rownames, I use
> rownames(bigframe2)<-unlist(lapply(framelist,rownames))
> Now, all I wonder is, why does this solution work and "rbind(framelist)"
> does not? (gives "Error in rbind(...) : cannot create a matrix from these
> types"). To my untrained eye, the two look identical...

In rbind(framelist) the argument is a single list.  do.call creates a call
in which framelist is mapped to several arguments.

There seems to be a lack of clarity in what cbind and rbind do, and I have
expanded the help page for the next patch release.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list