根据匹配将数据添加到列

时间:2013-12-06 11:39:07

标签: r merge union

我正在尝试将数据从一个数据框合并到另一个数据框。我想这对每个人来说都是一个简单的问题。但我似乎无法得到正确的结果。所以像。

df1 <- data.frame(X=c("aap","rel","kop"), Y=c(500,12,350))
df2 <- data.frame(X=c("lee","1su","eeu","ggu", "ees"), Y=c(100,12,350,80,50)) 
df3 <- merge(df1, df2)

结果应为:

df3 <- data.frame(X=c("aap","rel","kop", "lee","1su","eeu","ggu", "ees"), 
                 Y=c(500,12,350,100,12,350,80,50) 

1 个答案:

答案 0 :(得分:5)

您正在寻找

rbind(df1, df2)

    X   Y
1 aap 500
2 rel  12
3 kop 350
4 lee 100
5 1su  12
6 eeu 350
7 ggu  80
8 ees  50