Merging in R - merging what is similar...easy
I have two data frames like so:
A B
1 6
2 7
5 4
3 3
9 开发者_如何学Python 9
and the other one:
A C
1 5
5 9
3 1
9 1
and I want to merge them to create
A B C
1 6 5
5 4 9
3 3 1
9 9 1
notice that in the merged version, there is no A=2 because this does not show up in the second data frame (even though it shows up in the first). So basically, I want it to merge what exists, and leave out what doesn't. Currently, the merge fails completely because the two A columns are not exactly the same.
df2 <- data.frame(A=c(1,5,3,9), C=c(5,9,1,1))
df1 <- data.frame(A=c(1,2,5,3,9), B=c(6,7,4,3,9))
merge(df1,df2)
精彩评论