[R] merge function while obviating duplicate columns XXXX

Ista Zahn istazahn at gmail.com
Mon Mar 11 20:25:05 CET 2013


On Mon, Mar 11, 2013 at 3:17 PM, Dan Abner <dan.abner99 at gmail.com> wrote:
> Hi everyone,
>
> I have the following call to the merge() function. How does one
> prevent duplicate columns in the resulting data frame that the 2
> parent data frames have in common but are not true key or "by"
> variables?
>
>
> data3<-merge(data1,data2,by="id")
> data3
>
> id total.x total.y balance
> 1 78  78 90
> 2 91  91 63
> 3 74  74 57
> 4 89  89 58
> 5 90  90 27
>
>
> In this example, total is not a true key or "by" variable that
> uniquely identifies rows suitable for matching purposes, but instead
> just happens to be common to both sets.

Well, which one do you want? Or do you want to exclude total from the result?

>
> In reality, I have hundreds for these "in common" variables, so I need
> a solution that is tractable for a large number of "in common"
> columns.
>
> Thanks!
>
> Dan
>
> ______________________________________________
> 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