Last chance! 50% off unlimited learning
Sale ends in
Replace levels with "other"
fct_other(f, keep, drop, other_level = "Other")
A factor (or character vector).
keep
will preserve listed levels, replacing all others
with other_level
. drop
will replace listed levels with other_level
,
keeping all others as they are.
Value of level used for "other" values. Always placed at end of levels.
fct_lump()
to automatically convert the rarest (or most
common) levels to "other".
# NOT RUN {
x <- factor(rep(LETTERS[1:9], times = c(40, 10, 5, 27, 1, 1, 1, 1, 1)))
fct_other(x, keep = c("A", "B"))
fct_other(x, drop = c("A", "B"))
# }
Run the code above in your browser using DataLab