Recoding Categorical Variable

Hi, you could use case_when. It would be something like this. To make it easier for everyone, you should provide a reproducible example next time.

library(dplyr)

sleepdata_complete <- mutate(sleepdata_complete,
                             qualslp = as.factor(qualslp),
                             qualslp2 = case_when(qualslp %in% c("V Poor", "Poor", "Fair") ~ "Low",
                                                  TRUE ~ "High")) %>%
  mutate(qualslp2 = factor(qualslp2, levels = c("Low", "High")))