r - merge data.frame but keep only unique columns? -


let's want merge 2 data.frames of columns redundant (the same). how merge data.frames drop redundant columns?

x1 = data.frame(id = c("a","b","c"), same = c(1,2,3), different1 = c(4,5,6)) x2 = data.frame(id = c("b","c","a"), same = c(2,3,1), different2 = c(7,8,9))   merge(x1,x2, by="id", = true, sort = false)     id same.x different1 same.y different2 1       1          4      1          9 2  b      2          5      2          7 3  c      3          6      3          8 

but how different1 , different2 columns?

id same different1 different2 1     1     4      9 2  b    2     5      7 3  c    3     6      8 

you include column same in argument. default by=intersect(names(x), names(y)). try merge(x1, x2) (it same merge(x1, x2, by=c("id", "same"))):

 merge(x1,  x2)  #  id same different1 different2  #1     1          4          9  #2  b    2          5          7  #3  c    3          6          8 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -