Add additional levels to a factor
See also
fct_drop()
to drop unused factor levels.
Examples
f <- factor(sample(letters[1:3], 20, replace = TRUE))
f
#> [1] b b a b c b b a c a b c b c c c b c b a
#> Levels: a b c
fct_expand(f, "d", "e", "f")
#> [1] b b a b c b b a c a b c b c c c b c b a
#> Levels: a b c d e f
fct_expand(f, letters[1:6])
#> [1] b b a b c b b a c a b c b c c c b c b a
#> Levels: a b c d e f
fct_expand(f, "Z", after = 0)
#> [1] b b a b c b b a c a b c b c c c b c b a
#> Levels: Z a b c