将不相等的数据集与子组合并

时间:2017-12-07 18:34:15

标签: r merge grouping

我有两个不同大小的不同数据集。另外,一个人已经崩溃了。这是数据:

df = data.frame(ID = c(1L, 1L, 1L, 2L, 2L, 2L, 4L, 4L, 4L), 
            ID_name = c("AA", "AA", "AA", "BB", "BB", "BB", "DD", "DD", "DD"), 
            Volume = c(10L, 20L, 30L, 50L, 50L, 40L, 20L, 30L, 10L))

df1 = data.frame(ID = c(1L, 2L, 4L), 
                ID_name = c("AA", "BB","DD"), 
                Pop = c(2200L, 3300L, 2000L))

我希望我的结果看起来像这样

dfmerged = data.frame(ID = c(1L, 1L, 1L, 2L, 2L, 2L, 4L, 4L, 4L), 
                      ID_name = c("AA", "AA", "AA", "BB", "BB", "BB", "DD", "DD", "DD"), 
                      Volume = c(10L, 20L, 30L, 50L, 50L, 40L, 20L, 30L, 10L),
                      Pop = c(2200L, 2200L, 2200L, 3300L, 3300L, 3300L, 2000L, 2000L, 2000L))

dplyr有这样的功能吗?感谢

0 个答案:

没有答案