vec_duplicate_any(): detects the presence of any duplicated values,
in the same way as
vec_duplicate_detect(): returns a logical vector describing if each
element of the vector is duplicated elsewhere. Unlike
reports all duplicated values, not just the second and subsequent
vec_duplicate_id(): returns an integer vector given the location of
the first occurence of the value
vec_duplicate_any(x) vec_duplicate_detect(x) vec_duplicate_id(x)
A vector (including a data frame).
vec_duplicate_any(): a logical vector of length 1.
vec_duplicate_detect(): a logical vector the same length as
vec_duplicate_id(): an integer vector the same length as
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,
NaN are also considered to be equal.)
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_unique() for functions that work with the dual of duplicated
values: unique values.
vec_duplicate_any(1:10)#>  FALSEvec_duplicate_any(c(1, 1:10))#>  TRUEx <- c(10, 10, 20, 30, 30, 40) vec_duplicate_detect(x)#>  TRUE TRUE FALSE TRUE TRUE FALSE# Note that `duplicated()` doesn't consider the first instance to # be a duplicate duplicated(x)#>  FALSE TRUE FALSE FALSE TRUE FALSE# Identify elements of a vector by the location of the first element that # they're equal to: vec_duplicate_id(x)#>  1 1 3 4 4 6# Location of the unique values: vec_unique_loc(x)#>  1 3 4 6# Equivalent to `duplicated()`: vec_duplicate_id(x) == seq_along(x)#>  TRUE FALSE TRUE TRUE FALSE TRUE