Learn R Programming

broman (version 0.59-5)

lenuniq: Number of unique values

Description

Get the number of unique values in a vector

Usage

lenuniq(vec, na.rm = TRUE)

Arguments

vec
A vector
na.rm
If TRUE, remove any missing values

Value

  • Number of unique values.

Details

It just does length(unique(vec)) or, if na.rm=TRUE (the default) length(unique(vec[!is.na(vec)]))

Examples

Run this code
x <- c(1, 2, 1, 3, 1, 1, 2, 2, 3, NA, NA, 1)
lenuniq(x)
lenuniq(x, na.rm=FALSE)

Run the code above in your browser using DataLab