fct_drop: Drop unused levels

Description Usage Arguments See Also Examples

View source: R/drop.R

Description

Compared to base::droplevels(), does not drop NA levels that have values.

Usage

1
fct_drop(f, only)

Arguments

f

A factor (or character vector).

only

A character vector restricting the set of levels to be dropped. If supplied, only levels that have no entries and appear in this vector will be removed.

See Also

fct_expand() to add additional levels to a factor.

Examples

1
2
3
4
5
6
7
f <- factor(c("a", "b"), levels = c("a", "b", "c"))
f
fct_drop(f)

# Set only to restrict which levels to drop
fct_drop(f, only = "a")
fct_drop(f, only = "c")

tidyverse/forcats documentation built on Jan. 11, 2019, 11:10 a.m.