This is a faster version of length(unique(x)) that calls data.table::uniqueN().

n_distinct(..., na.rm = FALSE)

Arguments

...

vectors of values

na.rm

If TRUE missing values don't count

Examples

x <- sample(1:10, 1e5, rep = TRUE)
n_distinct(x)
#> [1] 10