Count unique values in a vector
Count the number of unique values in a vector. vec_count()
has two
important differences to table()
: it returns a data frame, and when
given multiple inputs (as a data frame), it only counts combinations that
appear in the input.
vec_count(x, sort = c("count", "key", "location", "none"))
x |
A vector (including a data frame). |
sort |
One of "count", "key", "location", or "none".
|
A data frame with columns key
(same type as x
) and
count
(an integer vector).
vec_count(mtcars$vs) vec_count(iris$Species) # If you count a data frame you'll get a data frame # column in the output str(vec_count(mtcars[c("vs", "am")])) # Sorting --------------------------------------- x <- letters[rpois(100, 6)] # default is to sort by frequency vec_count(x) # by can sort by key vec_count(x, sort = "key") # or location of first value vec_count(x, sort = "location") head(x) # or not at all vec_count(x, sort = "none")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.