R: Replace levels with "other"

fct_other {forcats} | R Documentation

## Replace levels with "other"

### Description

Replace levels with "other"

### Usage

    fct_other(f, keep, drop, other_level = "Other")

### Arguments

`f` | A factor.
`keep, drop` | `keep` will preserve listed levels, replacing all others `other_level`. `drop` will replace listed levels with `other_level` keep as they are.
`other_level` | Value of level used for "other" values. Always placed at end of levels.

### See Also

`fct_lump()` to automatically convert the rarest (or most common) levels to "other".

### Examples

    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"))

[Package forcats version 0.2.0 Index]