Compare two vectors
vec_compare(x, y, na_equal = FALSE, .ptype = NULL)
x, y | Vectors with compatible types and lengths. |
---|---|
na_equal | Should |
.ptype | Override to optionally specify common type |
An integer vector with values -1 for x < y
, 0 if x == y
,
and 1 if x > y
. If na_equal
is FALSE
, the result will be NA
if either x
or y
is NA
.
vec_compare()
is not generic for performance; instead it uses
vec_proxy_compare()
to
vec_cast_common()
with fallback
#> [1] 1 0 NA#> [1] 1 0 -1vec_compare(1:10, 5)#> [1] -1 -1 -1 -1 0 1 1 1 1 1#> [1] -1 -1 -1 -1 -1 1 1 1 -1 -1vec_compare(letters[1:10], "d")#> [1] -1 -1 -1 0 1 1 1 1 1 1#> [1] -1 0 1 1