[R] combine two data-frames into one

From: Suyan Tian <stian_at_mail.rockefeller.edu>
Date: Fri, 14 Mar 2008 15:43:42 -0400

Hi Everyone:

I need some help on combining two datasets into one. Since for those two datasets, there are different variables. Like

In dataset 1, I have

pt x1 x2
1 12 24
2 20 17

In dataset 2, I have
pt x2 x3
3 19 33
4 20 16

The final dataset I want should look as
pt x1 x2 x3
1 12 24 NA
2 20 17 NA
3 NA 19 33
4 NA 20 16

I used setdiff and rbind together and got what I wanted, but I am thinking there must be a simpler way to do this. Maybe just one command or something. Please help me out.

Thanks so many,


R-help_at_r-project.org 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. Received on Fri 14 Mar 2008 - 19:55:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 14 Mar 2008 - 20:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive