liveBook · Manning

Summarize() function

As explained in Statistics Slam Dunk

The summarize() function from dplyr reduces grouped or ungrouped data to summary values computed from its columns.

`summarize()` from dplyr reduces data to one or more summary values. Supply named calculations such as `mean(WS)`, `median(WS)`, `min(WS)`, `max(WS)`, or `sum(PTS)`; the names become columns in the result. The output is commonly a tibble, ready for further wrangling or a ggplot2 chart. section 2.5.3 section 19.3.1

Without grouping, calculations describe the whole input. Put `group_by()` earlier in a pipe to repeat them for every group: each group becomes a row in the result. This makes `summarize()` useful for questions such as how average career win shares vary by draft year, birthplace, college attendance, position, or draft-pick segment. section 2.5.3 section 2.5.5

A practical workflow is:

Compare career win shares by birthplace

Grouping NBA first-round selections by `Born2` and summarizing `mean(WS)` and `median(WS)` produces two rows: USA players average 31.1 career win shares with a 21.5 median, while World players average 23.5 with a 12.8 median. Those two measures can then be drawn as side-by-side bar charts. section 2.5.5

draft %>% 
 group_by(Born2) %>%
 summarize(meanWS = mean(WS),
           medianWS = median(WS)) -> tenth_tibble
print(tenth_tibble)
## # A tibble: 2 × 3
##   Born2 meanWS medianWS
##   <fct>  <dbl>    <dbl>
## 1 USA     31.1     21.5
## 2 World   23.5     12.8

This listing shows the compact pattern: group by a category, calculate multiple named summaries, and inspect the resulting tibble before visualization. section 2.5.5

`summarize()` can also consolidate records rather than merely describe them. After removing total-team rows, grouping player-season-position records and summing games and points merges multiple team stints into one record; columns not used as grouping keys or summary expressions do not remain in the result. section 19.3.1

How Statistics Slam Dunk covers it

How deep it goes
Explains piped, grouped and ungrouped calculations with means, medians, sums, percentages, and aggregation, without detailing dplyr internals.
Examples
Uses draft win shares, games played by pick segment, Bucks possessions, free-throw streaks, seasonal dispersion, and duplicate player records.
What it assumes
Introduces pipe flow and describes tibbles while using R functions such as mean, median, min, max, and sum.
What you can do after
Apply it via dplyr to compute named overall or per-group summaries and create plot-ready tibbles.
How it connects
Connects `summarize()` to `group_by()`, `filter()`, `mutate()`, tibbles, and ggplot2.

Related concepts

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.