两个数据集的首次合并:
Agg_Bpm <- merge(agg_bpm_mean, agg_bpm_median, by = "Group.1", all = TRUE, suffixes = c(".mean",".median"))
输出:
Group.1 x.mean x.median
1 2022484408 80.23686 76
2 2026352035 93.77631 95
3 2347167796 76.72279 73
4 4020332650 82.30058 83
5 4388161847 66.13300 62
现在我想合并另一个数据集:
> agg_bpm_max
Group.1 x
1 2022484408 203
2 2026352035 125
3 2347167796 195
4 4020332650 191
5 4388161847 180
所以我试试这个:
Agg_Bpm <- merge(Agg_Bpm, agg_bpm_max, by = "Group.1", all = TRUE, suffixes = c(c(".mean",".median"),".max"))
可以合并它,但如何正确地为新列添加后缀??
> Agg_Bpm
Group.1 x.mean x.median x
1 2022484408 80.23686 76 203
2 2026352035 93.77631 95 125
3 2347167796 76.72279 73 195
4 4020332650 82.30058 83 191
5 4388161847 66.13300 62 180
我决定一个简单的解决方案就是不使用后缀参数,只在以下事实之后重命名列:
> names(Agg_Bpm) <- c("id","mean","median","max","sd")
> Agg_Bpm
id mean median max sd
1 2022484408 80.23686 76 203 17.59559
2 2026352035 93.77631 95 125 12.61053
3 2347167796 76.72279 73 195 15.51571
4 4020332650 82.30058 83 191 15.91159
5 4388161847 66.13300 62 180 15.84728
你能试试吗:
Agg_Bpm <- merge(Agg_Bpm, agg_bpm_max, by = "Group.1", all = TRUE, suffixes = c("",".max"))
请下次提供可复制的数据集。您可以使用函数dput(Agg_Bpm)
进行此操作