• vec_unique(): the unique values. Equivalent to unique().

• vec_unique_loc(): the locations of the unique values.

• vec_unique_count(): the number of unique values.

vec_unique(x)

vec_unique_loc(x)

vec_unique_count(x)

## Arguments

x A vector (including a data frame).

## Value

• vec_unique(): a vector the same type as x containining only unique values.

• vec_unique_loc(): an integer vector, giving locations of unique values.

• vec_unique_count(): an integer vector of length 1, giving the number of unique values.

## Missing values

In most cases, missing values are not considered to be equal, i.e. NA == NA is not TRUE. This behaviour would be unappealing here, so these functions consider all NAs to be equal. (Similarly, all NaN are also considered to be equal.)

## Performance

These functions are currently slightly slower than their base equivalents. This is primarily because they do a little more checking and coercion in R, which makes them both a litter safer and more generic. Additionally, the C code underlying vctrs has not yet been implemented: we expect some performance improvements when that happens.

vec_duplicate for functions that work with the dual of unique values: duplicated values.

## Examples

x <- rpois(100, 8)
vec_unique(x)#>  [1] 12 11  6  7 10  5  9  8  4 17  3 14 16  2 13 19 15vec_unique_loc(x)#>  [1]  1  2  3  4  5  6  9 12 16 19 23 38 43 50 51 77 93vec_unique_count(x)#> [1] 17
# vec_unique() returns values in the order that encounters them
# use sort = "location" to match to the result of vec_count()
head(vec_unique(x))#> [1] 12 11  6  7 10  5head(vec_count(x, sort = "location"))#>   key count
#> 1  12     8
#> 2  11    12
#> 3   6    17
#> 4   7    10
#> 5  10    10
#> 6   5     8
# Normally missing values are not considered to be equal
NA == NA#> [1] NA
# But they are for the purposes of considering uniqueness
vec_unique(c(NA, NA, NA, NA, 1, 2, 1))#> [1] NA  1  2