liveBook · Manning

Data subsetting

As explained in Statistics Slam Dunk

Data subsetting is the selection of particular rows or columns from a dataset according to specified criteria.

Data subsetting selects particular rows or columns from a dataset according to criteria. It is a core data-wrangling step for removing irrelevant records and variables before analysis. section 2.3 section 6.3

Use subsetting to:

  • Filter rows that meet or fail a logical condition, such as excluding playoff records or retaining only road games. section 17.3
  • Select or deselect columns so an analysis keeps only the variables it requires. section 2.3 section 17.3
  • Check the resulting dimensions to confirm how many observations and variables remain. section 15.3

Preparing NBA betting data

Remove the 2019 playoffs, then retain the variables needed for game-level analysis:\n\n`oddsdf1 %>% filter(DATASET != "NBA 2019 Playoffs") -> oddsdf1`\n\n`oddsdf1 %>% select(GAME_ID, DATE, TEAM, VENUE, PTS, OPENING_SPREAD, OPENING_TOTAL, CLOSING_SPREAD, CLOSING_TOTAL) -> oddsdf1`\n\nThe same pattern can split road and home observations before the datasets are combined. section 17.3

Isolating a player’s records

Filter a free-throw dataset to Julius Randle, then verify the result: `ft %>% filter(player == "Julius Randle") -> randle`. The resulting data contains 350 attempts, and summing `points` confirms 257 makes. Further filtering removes the first record of each game and retains attempts following a make. section 16.4.2

oddsdf1 %>%
 filter(DATASET != "NBA 2019 Playoffs") -> oddsdf1

Inspect a complete row-subsetting expression that excludes NBA 2019 Playoffs records with dplyr’s filter(). section 17.3

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates executable row and column filtering with validation, but stops short of explaining implementation internals.
Examples
Uses NBA betting records, road and home team subsets, and Julius Randle free-throw observations.
What it assumes
Assumes imported datasets and basic R data objects while demonstrating wrangling decisions with imperfect real-world data.
What you can do after
Apply it via dplyr to filter observations, select variables, and verify resulting dataset dimensions.
How it connects
Connects data wrangling with logical criteria, variable selection, grouping, summarizing, reshaping, and joining datasets.

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.