[R] combine two data-frames into one

Henrique Dallazuanna wwwhsd at gmail.com
Fri Mar 14 20:57:09 CET 2008


Try:

 merge(x, y, all=T)

On 14/03/2008, 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.
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list