【发布时间】:2021-09-30 11:13:21
【问题描述】:
id1=c('1text','2text','3text')
df1=data.frame(id1)
df1
id1
1 1text
2 2text
3 3text
id2=c('2text','3text')
area2=c(11,22)
df2=data.frame(id2,area2)
df2
id2 area2
1 2text 11
2 3text 22
3 1text 33
我想将 area2 的数据添加到这些行中的数据框 df1 中,其中 id1=id2,所以我在 df1 中有一个带有该区域的新列。它应该是这样的:
id1 area1
1 1text NA
2 2text 11
3 3text 22
有人可以帮忙吗?
【问题讨论】:
-
merge(df1, df2, by.x = 'id1', by.y = 'id2')