liveBook · Manning

Categorical data

As explained in Statistics Slam Dunk

A categorical variable records observations as membership in one of a finite set of qualitative categories.

Categorical data places each observation into one of a fixed set of groups rather than measuring an amount. NBA examples include a player’s birth region, position, draft-pick segment, team, game venue, season, event type, and whether a free throw was made or missed. In R, these variables are commonly stored as factors. section 2.3.4 section 16.2

A value that looks numeric can still be categorical when its possible values are finite and represent groups. Draft year is treated as a factor because the data spans only 2000 through 2009; team likewise has a bounded set of possibilities. Converting genuine categories to factors is a best practice before modeling or visualization. section 2.3.4 section 6.3.2

Prepare categorical data by making the groups explicit:

Turn positions into analysis-ready groups

Raw player positions include C, C-F, F, F-C, F-G, G, and G-F. Recode them into broader labels such as Center, Big, Forward, Guard, and Swingman, then store both the original and grouped position variables as factors. This preserves the detailed labels while creating categories suitable for grouped analysis. section 2.3.5

Factors support analyses organized by levels. Grouping play-by-play records by event type produces counts for fouls, rebounds, shots, and other events. Factor levels can also define segments for boxplots, while categorical predictors can be paired with quantitative outcomes in ANOVA. section 8.4 section 14.5.1

draft$Pos2 <- draft$Pos
draft$Pos2 <- recode(draft$Pos2, 
                    "C" = "Center", 
                    "C-F" = "Big", 
                    "F" = "Forward", 
                    "F-C" = "Big", 
                    "F-G" = "Swingman", 
                    "G" = "Guard", 
                    "G-F" = "Swingman") 
draft$Pos <- as.factor(draft$Pos)
draft$Pos2 <- as.factor(draft$Pos2)
levels(draft$Pos2)
## [1] "Big"      "Center"   "Forward"  "Guard"    "Swingman"

Compare detailed position codes with the broader recoded factor levels used for analysis. section 2.3.5

How Statistics Slam Dunk covers it

How deep it goes
Defines fixed-value variables, demonstrates conversion and recoding, and applies factors in grouped analyses without detailing factor internals.
Examples
Uses draft year, teams, player positions, birth region, draft segments, play events, free throws, and standardized scoring categories.
What it assumes
Teaches factor conversion from basic character and numeric columns while introducing assignment, logical comparison, and missing-value handling as needed.
What you can do after
Apply it via base R functions to convert, inspect, recode, group, and visualize fixed-set variables as factors.
How it connects
Connects factors with data wrangling, missing values, data visualization, segmentation analysis, ANOVA, and chi-square testing.

Also explained in

Compare how 16 books explain categorical data →

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.