Collapsing of Factor Levels and Keeping Only Those New Group Levels
Source:R/utils_factor.R
fct_collapse_only.Rd
This collapses levels and only keeps those new group levels, in the order provided.
The returned factor has levels in the order given, with the possible missing level last (this will
only be included if there are missings). Note that any existing NA
in the input vector will
not be replaced by the missing level. If needed explicit_na()
can be called separately on the result.
Arguments
- .f
(
factor
orcharacter
)
original vector.- ...
(named
character
vectors)
levels in each vector provided will be collapsed into the new level given by the respective name.- .na_level
(
string
)
which level to use for other levels, which should be missing in the new factor. Note that this level must not be contained in the new levels specified in...
.
Value
The modified factor with collapsed levels. Values and levels which are not included in the given character vectors input will be set to the missing level.
See also
forcats::fct_collapse()
, forcats::fct_relevel()
which are used internally.