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
Place dplyr in the end-to-end flow after data import and before exploratory analysis, visualization, statistical testing, or modeling. section 1.3
