【发布时间】:2018-07-30 14:38:06
【问题描述】:
我想将两个数据帧合并到一个新的数据帧中,其中包含两个数据帧中的列,此外,我需要在新数据帧中只放入具有相同 ID 的行。
我的数据框看起来像:
df1
Name V1 V2 V3
str1 . . strA
str2 . . strB
.. . .
str16000 . . strC
df2
Name V1 V2 V3
str2 . . strD
str1 . . strE
.. . .
str20000 . . strF
我想要这样的输出:
Name df1$v3 df2$v3
str1 strA strE
str2 strB strD
注意 df1 和 df2 有不同的长度,而且 df1 和 df2 中的相同项目的位置不同。
谢谢大家
【问题讨论】:
-
如何
innerjoinlibrary(dplyr); inner_join(df1[c("Name", "V3")], df2[c("Name", "V3")], by = "Name")或使用mergefrombase R
标签: r dataframe merge intersect