Extracts the distinct values of an atomic vector, with the possibility to drop levels and remove missing values.
Value
(atomic vector()
) with distinct values in no particular order.
Examples
# for factors:
x = factor(c(letters[1:2], NA), levels = letters[1:3])
distinct_values(x)
#> [1] "a" "b"
distinct_values(x, na_rm = FALSE)
#> [1] "a" "b" NA
distinct_values(x, drop = FALSE)
#> [1] "a" "b" "c"
distinct_values(x, drop = FALSE, na_rm = FALSE)
#> [1] "a" "b" "c" NA
# for logicals:
distinct_values(TRUE, drop = FALSE)
#> [1] TRUE FALSE
# for numerics:
distinct_values(sample(1:3, 10, replace = TRUE))
#> [1] 1 3 2