Renaming categorical variables and their levels, for instance for summary tables, can be fiddly. This function accepts tibbles containing the old and new names for arguments and levels, and returns a dataframe (or list of dataframes, if one is passed) with variables and levels renamed.
rename_cat_variables(data, var_names = NULL, level_names = NULL)
A dataframe or list of dataframes (e.g., from multiple imputation) contains the variables. If a list is passed, it must have class "list"
A tibble containing old
and new
names for the variables. If NULL, only levels are renamed.
A tibble containing old var
names and level_old
and level_new
names. If NULL, only variables are renamed.
The dataframe or list of dataframes passed to data, with variables and/or levels renamed. Any variables where levels are renamed will be converted to factors.