liveBook · Manning

Cumsum() function

As explained in Statistics Slam Dunk

The cumsum() function returns the cumulative sums of the elements in a numeric vector.

cumsum() returns a vector of cumulative sums from another numeric vector. For 1, 2, and 3, it returns 1, 3, and 6. section 6.4.1

Build cumulative NBA totals

After counting first-quarter outcome categories and sorting them by frequency, add cumulative counts with mutate(cum_n = cumsum(n)). The resulting values are 783, 1333, 1698, and 1990; cumsum(pct_total) similarly produces cumulative percentages ending at 100.00. section 6.4.1

How Statistics Slam Dunk covers it

How deep it goes
Defines cumulative summation, demonstrates a three-value vector, and applies it inside mutate(); it does not explain implementation internals.
Examples
Uses the vector 1, 2, 3 and first-quarter NBA outcome counts to produce cumulative counts and percentages.
What it assumes
Assumes numeric vectors and basic dplyr pipelines while defining cumulative sums from a simple vector.
What you can do after
Apply it via R and dplyr to create running totals and cumulative percentages in a data frame.
How it connects
Connects cumulative summation with dplyr, mutate(), count(), arrange(), percentages, and data visualization.

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.