Use R’s base colnames() function to get or replace the column names of a matrix-like object, including a data frame or tibble. When replacing every name, provide a character vector whose length equals the object’s number of columns. section 6.4.6
Rename a results table
After grouping tied-at-halftime NBA games, replace tbl21’s difficult logical-expression headers with compact names: colnames(tbl21) <- c('HHH', 'HRH', 'RHH', 'RRR', 'RHR', 'HRR', 'count') head(tbl21, n = 1) The resulting columns identify quarter-and-game outcomes, followed by their counts. section 6.4.6
colnames(tbl21) <- c('HHH', 'HRH', 'RHH', 'RRR', 'RHR', 'HRR', 'count')
head(tbl21, n = 1)
## # A tibble: 1 × 7
## # Groups: HHH, HRH, RHH, RRR, RHR [1]
## HHH HRH RHH RRR RHR HRR count
## <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <int>
## 1 FALSE FALSE FALSE FALSE FALSE TRUE 6
Inspect the renamed headers and first data row before continuing with type conversion and table reshaping. section 6.4.6
