Re: [R] Union of two data frames

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 20 Sep 2006 - 01:17:18 GMT

Try either of these:

rbind(DF1, DF2[setdiff(rownames(DF2), rownames(DF1)),])

rbind(DF1, DF2[!(rownames(DF2) %in% rownames(DF1)),])

On 9/19/06, Kartik Pappu <kartik.pappu@gmail.com> wrote:
> Hi all,
>
> I have two data frames each with 5 columns and different number of
> rows. some of the row names in one data frame are the same as the row
> names in the other. I want to be able to merge the two data frames to
> get a new data frame in which the duplicated row names are only shown
> once with the data for the rest of the columns used from the first
> data frame.
>
> for example:
>
> Pvals PD
> A 0.001 0.99
> B 0.02 0.98
> C 0.05 0.97
> D 0.005 0.99
>
> Pvals PD
> C 0.01 0.99
> D 0.0002 0.98
> E 0.05 0.97
> F 0.02 0.99
>
> Union
> Pvals PD
> A 0.001 0.99
> B 0.02 0.98
> C 0.05 0.97
> D 0.005 0.99
> E 0.05 0.97
> F 0.02 0.99
>
> Essentially, I want to make a union of the two data frames. I hope
> this question makes sense.

>
> Thanks
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>



R-help@stat.math.ethz.ch 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 Wed Sep 20 11:21:19 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 20 Sep 2006 - 02:30:05 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.