`select()` from dplyr reshapes a data frame’s column set: retain needed variables, drop unneeded ones, or arrange the remaining columns in a new order. It is a practical first step when wide NBA data contains fields that do not serve the analysis. section 2.3.1 section 14.2.4
Pass column names to keep them, or prefix selections with `-` to remove them. Columns can also be selected by position, contiguous ranges, or helpers such as `starts_with()`. Naming columns is generally preferred to positions, unless names create errors or many columns must be removed. section 2.3.1 section 9.3
Use `select()` to prepare a focused data set for the next operation:
- Keep a small analytical set, such as `select(DATASET, TEAM, VENUE, FT, FTA, PF)`, before renaming and combining road and home records. section 7.3
- Keep a consecutive run of columns with `select(DATASET:MIN)` rather than listing every variable individually. section 6.3.2
- Drop unwanted ranges with `select(-c(OT1R:OT5R, MINR, OT1H:OT5H, MINH))`. section 6.3.2
- Reorder retained columns by passing all of them in the desired sequence, such as `select(Team, season, PTS, O_PTS, PTS_DIFF)`. section 14.2.4
Trim a draft data set
To remove superfluous career statistics by position, pipe the data frame into `select()` and use a negative selection. The result retains every column except positions 3, 4, and 16 through 24. section 2.3.1
draft <- select(draft,-c(3,4,16:24))
Inspect a minimal executable example of negative positional selection with `select()`. section 2.3.1
