len_uniq: Number of unique values

View source: R/len_uniq.R

len_uniqR Documentation

Number of unique values

Description

Get the number of unique values in a vector. Borrowed from Karl Borman. Source: https://github.com/kbroman/broman/blob/master/R/lenuniq.R

Usage

len_uniq(vec, na.rm = TRUE)

Arguments

vec

A vector

na.rm

If TRUE, remove any missing values

Details

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

Value

Number of unique values.

Examples

x <- c(1, 2, 1, 3, 1, 1, 2, 2, 3, NA, NA, 1)
len_uniq(x)
len_uniq(x, na.rm=FALSE)

emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.