我目前有多个表需要合并。例如,我有tbl_1,tbl_2和tbl_3。我想以结果表的形式达到最终结果。R合并具有一个标识符的表和其他具有相同名称的列会加起来
tbl_1:
ID trx_1 Cre_counts Deb_counts
1 10 9 8
2 5 6 5
3 10 4 3
tbl_2:
ID trx_2 Unk_counts Deb_counts
1 10 1 2
2 5 6 5
3 10 3 7
tbl_3:
ID trx_3 Unk_counts Ckc_counts
1 3 4 4
2 2 4 3
3 8 7 6
result:
ID trx_1 tx_2 trx_3 Cre_counts Deb_counts Unk_counts Ckc_counts
1 10 10 3 9 10 5 4
2 5 5 2 6 10 10 3
3 10 10 8 4 10 10 6
我有尝试通过“ID”合并三个表,但列名会变为Deb_counts.x,Deb_counts.y ......我可以使用变换(),rowSums()采取一些额外的步骤使其工作。但我想知道有没有更简单的方法来做到这一点?谢谢!
,要合并一些值并添加其他值,则需要进行至少2 ST eps – Cath
是的,我明白这一点。目前,我正在采取的步骤不止两个步骤。我首先合并所有表格,然后使用rowSums()添加我想要添加的所有列。然后,删除旧的列。只是想知道你是否知道更简单的方法来做到这一点?也许只有2个步骤。 – VeraShao
嗨,希望这个链接帮助,几乎相同的问题。 https://stackoverflow.com/questions/16018863/combine-data-frames-summing-up-values-of-identical-columns-in-r – Wen