Working with categorical data in R without losing your mind
summary
Shows concrete failures with R factors — numeric-to-level conversion giving wrong numbers, lost counts when levels mismatch, a trailing space turning values into NA — using the General Social Survey as the running example. Demonstrates robust fixes with base R and the tidyverse and highlights the forcats functions forcats, stringsAsFactors=TRUE historical pitfalls, and practical defenses like running summary/assertion tests and checking factor levels across training/testing splits. Watch if needing repeatable, safer workflows for categorical wrangling.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 0:30Practical Data Science for Stats
- 1:19Teaching introductory statistics classes
- 2:40Categorical data
- 3:44Why categorical data
- 4:32Writing the paper
- 4:48The paper
- 5:14Factors behave unexpectedly
- 6:27Reading as factors
- 6:55Strings as factors
- 8:26Why you need factors
- 9:13Ugly factors code
- 10:42Bad approaches
- 13:35Robust approaches
- 14:00Hadley Wickham
- 15:40Cheat Sheet
- 16:31Comparison
- 18:05Defensive coding
- 19:32Summary
related talks
48mCommon Data Science Mistakes
05mImplications of R Syntax in Intro Stats
51mProgramming in the Tidyverse
46mElegant R: Tips from a Software Developer
47mWhat Makes a Good Function
22mModelling, Tidyverse Way
37mHow to Start Critical Thinking in Data Science
48mHuman data interactions: experiments in how humans analyze data
