Skip to contents

This function recodes factors by combining some of the original factor levels together.

Usage

group_some_factor_levels(df, map)

Arguments

df

data.frame

map

Named list

Value

df with factors in names(map) recoded with combined levels

Details

The names in map correspond to the factor names in df whose levels need to be combined. Each element in map is a list with one or more vector(s) of factor levels to combine together, using the first element in each vector as the value for all levels in that vector.

Examples

if (FALSE) {
map <- list(Nationality=list(c("US", "Puerto Rico"), c("Canada", "Quebec")))
df <- df |> group_some_factor_levels(map)
}