开发者

Merging in R - merging what is similar...easy

开发者 https://www.devze.com 2023-04-12 07:20 出处:网络
I have two data frames like so: AB 16 27 54 33 9开发者_如何学Python9 and the other one: AC 15 59 31 91 and I want to merge them to create

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号