powered by
Get the number of unique values in a vector
lenuniq(vec, na.rm = TRUE)
Number of unique values.
A vector
If TRUE, remove any missing values
TRUE
It just does length(unique(vec)) or, if na.rm=TRUE (the default) length(unique(vec[!is.na(vec)]))
length(unique(vec))
na.rm=TRUE
length(unique(vec[!is.na(vec)]))
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