I can get case_when to write a NUMBER in a data frame, but not a string of text.
My code is like this:
df$Recoded_q1 <- case_when(
(df$q1 == 1 | df$q1 == 2) ~ 1,
(df$q1 == 3 | df$q1 == 4) ~ 2,
(df$q1 == 5 | df$q1 == 6) ~ 3,
TRUE ~ as.numeric(df$q1)
All works well like this, but I can't change the 1, 2, and 3 to text-based, categorical names like "low", "medium", and "high".
Any insight? I've tried double quotes and single quotes both and get errors.