Manually combine levels of categorical data.
Value
A data.frame with the predictor's levels combined. The
predictor keeps its original position among the columns.
Details
Levels are matched exactly, not as regular expressions. Only the
selected levels are renamed; other levels are left untouched even when
their names contain the selected name as a substring.
Unselected explicit NA levels and missing codes are preserved, as is
the ordered class. A combined level takes the position of its first selected
level; a new level for missing codes alone is appended at the end.
Examples
upper <- c("secondary", "tertiary")
out <- rbin_factor_combine(mbank, education, upper, "upper")
table(out$education)
#>
#> upper unknown primary
#> 3651 179 691
out <- rbin_factor_combine(mbank, education, c("secondary", "tertiary"), "upper")
table(out$education)
#>
#> upper unknown primary
#> 3651 179 691