【发布时间】:2018-07-27 07:38:20
【问题描述】:
我想合并来自不同数据帧的不同长度的 19 列并进行比较。这是一个例子:
df1:
PA0001
PA0002
PA0003
PA0004
PA0005
df2:
PA0001
PA0003
PA0006
PA0007
df3:
PA0001
PA0007
等等……
输出是这样的:
PA0001 | PA0001 | PA0001
PA0002 | NA | NA
PA0003 | PA0003 | NA
PA0004 | NA | NA
PA0005 | NA | NA
NA | PA0006 | NA
NA | PA0007 | PA0007
我使用了compare 或merge 函数,但我没有得到好的结果。我试过用这个问题的功能:Link
但我得到了这个错误:
Error in attributes(.Data) <- c(attributes(.Data), attrib) :
'names' attribute [5254] must be the same length as the vector [2]
这是你的例子:
test1 <- data.frame(c("PA0001","PA0002","PA0003","PA0004","PA0005","PA0006"))
test2 <- data.frame(c("PA0001","PA0002","PA0004","PA0005","PA0007"))
test3 <- data.frame(c("PA0001","PA0004","PA0005","PA0007", "PA0008"))
非常感谢。
【问题讨论】:
-
请阅读您阅读的问题的答案。 ...
stringsAsFactors = FALSE。你必须强制你的列来改变字符。 -
@jogo 我做到了,我得到了这个错误
Error in attributes(.Data) <- c(attributes(.Data), attrib) : 'names' attribute [5254] must be the same length as the vector [2]只使用一列并使用不同的名称。 -
对我来说,答案stackoverflow.com/a/43266762/5414452 与
df1 = data.frame(TEST1=c("PA0001","PA0002","PA0003","PA0004","PA0005","PA0006"), stringsAsFactors = FALSE)一起使用,依此类推 -
您创建的示例和您展示的输入/输出不同
标签: r merge multiple-columns