我有两个数据帧,如何在R中的两个列数据框之间插入一个具有匹配条件的列?
DF1
Identifier GSE1028888 GSE1034555
100002 0.1 0.2
100003 0.3 0.4
...... ..... .....
100007 0.9 1.1
DF2
V3 V2
100002 XLX12
100003 ABorF
...... .....
110000 GEF22
现在我想插入V2信息到DF1,如
DF3
Identifier New_V2 GSE1028888 GSE1034555
100002 XLX12 0.1 0.2
100003 ABorF 0.3 0.4
100004 NA 0.6 0.7
...... ..... .....
100007 ccL34 0.9 1.1
df2的V3和df1的标识符具有不同的长度。 我尝试dplyr left_join,但该列附在最后。
这是代码来创建类似的数据帧
df1 <- data.frame("Identifier" = sample(100001:100010, 6, replace = F),
y = sample(rnorm(10), 6, replace = T),
z = sample(rnorm(10), 6, replace = T))
df2 <- data.frame(V1 = c(100001:100010),
V2 = sample(state.name, 10, replace = T))
这个时候,当我尝试dplyr left_join,
left_join(df1, df2, by =c("Identifier"="V3"))
显示出错误消息
Error: cannot join on columns 'V3' x 'Identifier': index out of bounds
任何人有任何理念?
您的问题不包含[reproducible example](http://stackoverflow.com/q/5963269/4303162)。因此很难理解你的问题并给你一个合适的答案。请提供您的数据(例如使用'dput()')或使用R中的示例数据集之一。另外,添加将您的问题重现到您的文章所需的最小代码。 – Stibu