Skip to contents

Replaces NA factor values with an explicit category name. Name is ensured to be different from all existing levels. So it's like forcats::fct_explicit_na but if the level specified to na_level happens to be present among levels of x, it puts additional brackets until it's different.

Usage

fct_explicit_na_auto(x, na_level = "(Missing)")

Arguments

x

A factor (or character vector).

na_level

Level to use for missing values: this is what NAs will be changed to.

Examples

x <- factor(c("a", "b", "(Missing)", NA))
fct_explicit_na_auto(x)
#> [1] a           b           (Missing)   ((Missing))
#> Levels: (Missing) a b ((Missing))