How to calculate cumulative sum? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-27 16:07:52

问题


I have data containing columns biweek and Total, I want to get cumulative sum on biweek basis. My data is like:

biweek  Total
0   3060.913
1   4394.163
2   3413.748
3   2917.548
4   3442.055
5   3348.398
6   1771.722

and I want to get output like :

biweek  Total
0   3060.913
1   7455.076
2   10868.824
3   13786.372
4   17228.427
5   20576.825
6   22348.547

So it there a possible way to achieve it?


回答1:


# replace the second column for the cumsum of the initial second column
data[, 2] <- cumsum(data[, 2])


来源:https://stackoverflow.com/questions/40042711/how-to-calculate-cumulative-sum

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!