merge_levels: Combine specified levels of a factor

View source: R/merge_levels.R

merge_levelsR Documentation

Combine specified levels of a factor

Description

Similar to merge_factor() but generally reserved for situations when you don't need to worry about specifying the entire factor. Instead of taking a list of arguments as input, it takes named values. The old levels that aren't altered stay put order-wise, and the new ones are swapped in to where their old levels were, as much as possible.

Usage

merge_levels(.data, ...)

Arguments

.data

The factor you want to re-specify.

...

Values that must be named, where the name corresponds to the new level and the value corresponds to the old level. The values can be strings, numbers, of vectors of those.

Value

a factor with levels and values as you specified, with those unspecified not changing.

See Also

merge_factor

Examples

my_factor <- factor(c("d", "b", "c", "d", "a", "a"))
levels(my_factor)
merge_levels(my_factor, "AandB"=c("a","b"), "RenamedC"="c")


burchill/zplyr documentation built on Feb. 2, 2023, 11:01 a.m.