[R] combine two data-frames into one

John Kane jrkrideau at yahoo.ca
Fri Mar 14 21:03:16 CET 2008


library(reshape) 
?rbind.fill


--- Suyan Tian <stian at mail.rockefeller.edu> wrote:

> 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,
> 
> Suyan
> 
> ______________________________________________
> 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.
>



More information about the R-help mailing list