使用具有多个数据帧的合并功能

时间:2017-04-10 07:59:09

标签: r merge

我有这种数据的不同数据框架。

DF1
Name    |   Accession  | Character | %    |
P07437  |  beta        |  SJ       | 55   |
P07137  |  alpha       |  SA       | 66   |
P07677  |  beta        |  SI       | 65   |
P07437  |  alpha       |  ST       | 12   |

DF2
Name    |   Accession  | Character | %    |
P0225  |  beta        |  SJ       | 55   |
P0757  |  alpha       |  SA       | 66   |
P0377  |  beta        |  SI       | 65   |
P0137  |  alpha       |  ST       | 12   |

DF3
Name    |   Accession  | Character | %    |
P0357  |  beta        |  SK       | 55   |
P1540  |  beta       |  SA       | 66   |
P2367  |  gamma        |  SI       | 65   |
P6985  |  alpha       |  ST      | 12   |

DF4
Name    |   Accession  | Character | %    |
P07437  |  beta        |  SJ       | 55   |
P07137  |  beta       |  SA       | 66   |
P07677  |  alpha       |  SI       | 65   |
P07437  |  alpha       |  ST       | 12   |

当我尝试将merge函数与两个data.frame一起使用时,输出是正确的:

df_final <- merge(df1, df2  by=c("Name", "Accession"),all=TRUE)

但是当我尝试使用包含3个或更多数据帧的合并功能时,我得到了这个错误:

df_final <- merge(df1, df2, df3, df4,  by=c("Name", "Accession"),all=TRUE)


Error in fix.by(by.x, x) : 
  'by' must specify one or more columns as numbers, names or logical

有没有办法将merge function用于多个数据框?

这是一个可重现的例子:

df1 <- data.frame(Name=c("P07137","P07677","P07437"), Accession=c("alpha","beta","beta"), Character=c("SJ","SA","SS"), Percentage=c(5,10,25))

df2 <- data.frame(Name=c("P0225","P0757","P0337"), Accession=c("alpha","beta","beta"), Character=c("SJ","SA","SS"), Percentage=c(5,10,25))

df3 <- data.frame(Name=c("P02137","P17677","P87437"), Accession=c("alpha","alpha","beta"), Character=c("SU","SS","ST"), Percentage=c(5,10,25))

df4 <- data.frame(Name=c("P0057","P07677","P07437"), Accession=c("alpha","beta","beta"), Character=c("SJ","SA","SS"), Percentage=c(5,10,25))

提前谢谢你。

`

0 个答案:

没有答案