Returns the number of unique values in the input vector

n_unique(x, to_unlist = FALSE)

Arguments

x

input vector

to_unlist

boolean of whether to flatten the input with unlist(); default is FALSE

Examples

n_unique(c(1, 2, 3, 3, 4))
#> [1] 4
n_unique(c("A", "B", "C", "D", "A"))
#> [1] 4
n_unique(list(letters[1:5], letters[1:4]))
#> [1] 2
n_unique(list(letters[1:5], letters[1:4]), to_unlist = TRUE)
#> [1] 5