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
