r - How do I combine two data-frames based on two columns? -



r - How do I combine two data-frames based on two columns? -

this question has reply here:

how bring together (merge) info frames (inner, outer, left, right)? 10 answers

i know can utilize plyr , friends combine dataframes, , merge well, far don't know how merge 2 dataframes multiple columns based on 2 columns?

see documentation on ?merge, states:

by default info frames merged on columns names both have, separate specifications of columns can given by.x , by.y.

this implies merge merge info frames based on more 1 column. final illustration given in documentation:

x <- data.frame(k1=c(na,na,3,4,5), k2=c(1,na,na,4,5), data=1:5) y <- data.frame(k1=c(na,2,na,4,5), k2=c(na,na,3,4,5), data=1:5) merge(x, y, by=c("k1","k2")) # na's match

this illustration meant demonstrate utilize of incomparables, illustrates merging using multiple columns well. can specify separate columns in each of x , y using by.x , by.y.

r merge data.frame

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -