我有一个这样的数据框:
data=data.frame(ID=c("0001","0002","0003","0004","0004","0004","0001","0001","0002","0003"),Saldo=c(10,10,10,15,20,50,100,80,10,10),place=c("grocery","market","market","cars","market","market","cars","grocery","cars","cars"))
我试图计算 ID 变量中每个人的 aldo 总和,应用 cumsum 或 apply 但我没有得到我想要的结果。我想要这样的人:
ID Saldo.Total
1 0001 190
2 0002 20
3 0003 20
4 0004 85