[R] merge function while obviating duplicate columns XXXX

Dan Abner dan.abner99 at gmail.com
Mon Mar 11 20:17:44 CET 2013


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.

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



More information about the R-help mailing list