如何计算累计金额?
How to calculate cumulative sum?
我有包含列 biweek
和 Total
的数据,我想在 biweek
的基础上获得累计总和。我的数据是这样的:
biweek Total
0 3060.913
1 4394.163
2 3413.748
3 2917.548
4 3442.055
5 3348.398
6 1771.722
我想得到这样的输出:
biweek Total
0 3060.913
1 7455.076
2 10868.824
3 13786.372
4 17228.427
5 20576.825
6 22348.547
那么有什么方法可以实现吗?
# replace the second column for the cumsum of the initial second column
data[, 2] <- cumsum(data[, 2])
我有包含列 biweek
和 Total
的数据,我想在 biweek
的基础上获得累计总和。我的数据是这样的:
biweek Total
0 3060.913
1 4394.163
2 3413.748
3 2917.548
4 3442.055
5 3348.398
6 1771.722
我想得到这样的输出:
biweek Total
0 3060.913
1 7455.076
2 10868.824
3 13786.372
4 17228.427
5 20576.825
6 22348.547
那么有什么方法可以实现吗?
# replace the second column for the cumsum of the initial second column
data[, 2] <- cumsum(data[, 2])