The c() function is a base R combining function: pass multiple arguments to concatenate them into a vector. Vectors can supply variable positions, names, season values, or package names to other functions. section 2.3.1 section 3.2
Use c() in several practical data-preparation patterns:
- Remove selected variables with dplyr::select() by placing a minus sign before c(), as in select(-c(off_loose_balls, def_loose_balls)). section 5.3
- Filter out several values with %in% and logical negation: gini[!(gini$season_end %in% c(1985, 1986, 1987, 1988, 1989, 1990)),]. section 12.4
- Pass several package names to lapply() after creating a character vector with c("tidyverse", "networkD3", "patchwork"). section 3.2
Dropping incomplete NBA seasons
The season_end values 1985 through 1990 become one vector, and %in% checks each row against that vector. Because ! negates the match, the resulting gini3 data excludes those seasons and contains 12,929 rows and three columns. section 12.4
draft <- select(draft,-c(3,4,16:24))
Inspect a compact select() example that removes draft-data columns by position using the negative c() pattern. section 2.3.1
