Learn R Programming

dplyr (version 0.5.0)

n_distinct: Efficiently count the number of unique values in a set of vector

Description

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

Usage

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

Arguments

na.rm

id TRUE missing values don't count

vectors of values

Examples

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

Run the code above in your browser using DataLab