Cumulative sum or count in R Here is how to calculate cumulative sum or count by using R built-in datasets.