fct_collapse: Collapse factor levels into manually defined groups

PHOTO EMBED

Wed Jun 01 2022 05:46:45 GMT+0000 (Coordinated Universal Time)

Saved by @Treenose #r

vector_with_old_varnames_to_be_collapsed <- c("Var", "var", "Variable", "variables")

df %>% 
  mutate(collapsed_variables = fct_collapse(variables_column, 
                                     Variable = vector_with_old_varnames_to_be_collapsed)))
content_copyCOPY

Different spellings of the same variable that needed to be collapsed into one variable.