Transforms categorical data by combining its levels according to a given
lumping, such as one previously found by maximum_mutual_information_nominal().
This makes it possible to reuse a lumping, for example one learned on
training data, on new data.
Arguments
- data
Factor or character vector of the categorical data.
- lumping
Named list of character vectors, where each vector contains the original levels that are combined into a new level named after the entry. If the list is unnamed, names are generated with
level_namer.- level_namer
Function that takes a character vector of the original levels in a lump and returns the name of the new lumped level. Only used when
lumpingis unnamed. Default: concatenating the original levels with a "+" in between.
Details
Levels that appear in the lumping but not in the data are kept as empty
levels, so that applying the same lumping always yields the same factor
levels. Conversely, levels that appear in the data but not in the lumping
are replaced by NA, with a warning.
See also
lump_nominal() to find and apply the optimal lumping in one step.
apply_ordinal_lumping() for the ordinal analogue of this function.
