liveBook · Manning

Dplyr

As explained in Statistics Slam Dunk

dplyr is an R package providing a grammar of functions for transforming and summarizing tabular data.

dplyr is an R package for transforming and summarizing tabular data. Use its functions to reduce a data set to needed columns, keep matching rows, arrange records, create variables, group observations, and combine data sets. These operations form the practical preparation step between importing messy data and analyzing or visualizing it. section 1.3

Workflows commonly use the pipe operator (%>%) to pass a data set through a sequence of clear actions. A useful pattern is to filter records, group them by a meaningful variable, then summarize a statistic or count. The result is a tibble: a compact table ready for interpretation, further analysis, or plotting. section 2.5.3 section 12.4

Core operations shown in practical data work include:

  • Use select() to retain only variables needed for an analysis, such as salary, season, and team. section 12.4
  • Use filter() to retrieve rows meeting conditions, such as a particular team and season or players above a win-share threshold. section 2.5.3 section 12.4
  • Use group_by() with summarize() to calculate a statistic separately for each group, such as mean win shares by draft year. section 2.5.3
  • Use arrange(), group_by(), mutate(), and filter() together to rank salaries within each team-season and retain selected ranks. section 12.4

Compare NBA draft classes

To compare career win shares across draft years, group the draft table by Year and summarize the mean of WS. To focus on highly productive players, first filter for WS of at least 75, then group by Year and summarize average draft position. This turns player-level records into questions about which draft classes produced stronger outcomes. section 2.5.3

Trim and rank salary records

Start with salary, season, and team; remove early seasons with sparse records; arrange each team-season by salary; assign a descending salary rank with mutate(); then keep ranks through 14. Each step makes an explicit wrangling decision before measuring salary inequality. section 12.4

Figure 1.5 A typical chapter flow and, not coincidentally, the typical end-to-end flow of most real-world data science and statistics projects
CH01_F05_Sutton

Place dplyr in the end-to-end flow after data import and before exploratory analysis, visualization, statistical testing, or modeling. section 1.3

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates executable filtering, selection, grouping, summaries, arrangement, mutation, and ranking rather than package internals.
Examples
Uses NBA draft win shares, team salary records, franchise data, and grouped yearly summaries as working tables.
What it assumes
Assumes familiarity with loading packages and basic data frames while revisiting dplyr and tidyr for repeated wrangling work.
What you can do after
Apply it via dplyr to select, filter, group, summarize, rank, and reshape analysis-ready NBA data.
How it connects
Connects data wrangling with tidyr, readr, ggplot2, sqldf, exploratory data analysis, and data standardization.

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.