n_distinct {dplyr} | R Documentation

## Efficiently count the number of unique values in a vector.

### Description

This is a faster and more concise equivalent of `length(unique(x))`

### Usage

    n_distinct(x, na_rm = FALSE)

### Arguments

`x` | a vector of values
`na_rm` | if `TRUE` missing values don't count

### Examples

    x <- sample(1:10, 1e5, rep = TRUE)
    length(unique(x))
    n_distinct(x)

[Package dplyr version 0.4.3 Index]