index type.x type.y col3 col4
1 a m 20 25
2 b m 30 28
3 a m 15 555
3 a n 20 555
4 a m 666 10
4 b m 666 20
当我尝试获得以下形状时,我尝试过将索引和group_by保持聚合但没有成功:
index col3 col4
1 20 25
2 30 28
3 35 555
4 666 30
如果您使用的base R
是以下代码,则可能会有所帮助
r <- aggregate(df[4:5],by = df[1],function(v) sum(unique(v)))
这使
> r
index col3 col4
1 1 20 25
2 2 30 28
3 3 35 555
4 4 666 30
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句