Skip to content

fct_unique() extracts the complete set of possible values from the levels of the factor, rather than looking at the actual values, like unique().

fct_unique() only uses the values of f in one way: it looks for implicit missing values so that they can be included in the result.

Usage

fct_unique(f)

Arguments

f

A factor.

Value

A factor.

Examples

f <- fct(letters[rpois(100, 10)])
unique(f)     # in order of appearance
#>  [1] o l k q g i j r h n f b m e p c d s
#> Levels: o l k q g i j r h n f b m e p c d s
fct_unique(f) # in order of levels
#>  [1] o l k q g i j r h n f b m e p c d s
#> Levels: o l k q g i j r h n f b m e p c d s

f <- fct(letters[rpois(100, 2)], letters[1:20])
unique(f)     # levels that appear in data
#> [1] c b e a d f
#> Levels: a b c d e f g h i j k l m n o p q r s t
fct_unique(f) # all possible levels
#>  [1] a b c d e f g h i j k l m n o p q r s t
#> Levels: a b c d e f g h i j k l m n o p q r s t