如何创建逐步累积的数据?

How to create a step-by-step cumulation of data?

可能我的问题真的很无聊,但我找不到简单的解决方案。所以我们有一个 data.frame without (整体)列。总体列必须显示在特定时间段内吃掉的馅饼的累计数量(在我的例子中)。在 R 中为无限行创建它的最简单方法是什么?谢谢!

  Year Pies eaten Pies eaten(overall)
1 1960 3          3
2 1961 2          5
3 1962 5          10
4 1963 1          11
5 1964 7          18
6 1965 4          22

我们可以使用cumsum

df1$Pies_eaten_Overall <- cumsum(df1$Pies_eaten)