[R] Merging data.frames

Richard A. Bilonick rab at nauticom.net
Wed Mar 8 15:59:07 CET 2000


Mark Lamias wrote:

> On Tuesday, March 07, 2000 5:40 PM, Richard Bilonick wrote:
>
> >I need to merge several data.frames into one data.frame. In S-Plus  I would
> >use
> >"merge" but I don't see a merge command in R. What is the best way to
> >accomplish
> >this?
>
> The easiest way to to this, I think, is as follows:
>
> if you have several data frames, dataframe1, dataframe2, . . . , dataframen,
> you can merger them all into one dataframe by using the data.frame command
> again with the individuaal data.frames as arguments:
>
>         data.frame(dataframe1, dataframe2, . . . , dataframen)
>
> here's a quick example:
>
> > a1_c(1, 1, 1)
> > a2_c(2, 2, 2)
> > b1_c(3, 3, 3)
> > b2_c(4, 4, 4)
>
> > adf_data.frame(a1,a2)
> > bdf_data.frame(b1,b2)
> > adf+bdf
>   a1 a2
> 1  4  6
> 2  4  6
> 3  4  6
> > data.frame(adf, bdf)
>   a1 a2 b1 b2
> 1  1  2  3  4
> 2  1  2  3  4
> 3  1  2  3  4
> > data.frame(adf, bdf, adf)
>   a1 a2 b1 b2 a1 a2
> 1  1  2  3  4  1  2
> 2  1  2  3  4  1  2
> 3  1  2  3  4  1  2
>
> I hope this helps.
>
> Mark J. Lamias
> Department of Statistics
> Department of Political Science
> Survey Methodology Program/Survey Research Center
> Institute for Social Research - University of Michigan
> 426 Thompson Street, Room 315
> Ann Arbor, Michigan 48104-2321
> (734) 647-5381
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Unfortunately it does not help. I need to concatenate the records vertically, not
horizontally. Each data.frame has the same variables. One data.frame may have 10
records and the other has 20 records. I want a new data.frame with all 30 records.
If these were matrices I would use rbind. Unfortunately rbind does not work nicely
with data.frames.

Rick Bilonick

--
Statistical Consulting for Business & Industry
mailto:rab at nauticom.net
efax:  508 445 5821
voice: 412 831 4509



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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