| vec_match {vctrs} | R Documentation |
vec_in() returns a logical vector based on whether needle is found in
haystack. vec_match() returns an integer vector giving location of
needle in haystack, or NA if it's not found.
vec_match(needles, haystack) vec_in(needles, haystack)
needles, haystack |
Vector of
|
vec_in() is equivalent to %in%; vec_match() is equivalent to match().
A vector the same length as needles. vec_in() returns a
logical vector; vec_match() returns an integer vector.
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.)
hadley <- strsplit("hadley", "")[[1]]
vec_match(hadley, letters)
vowels <- c("a", "e", "i", "o", "u")
vec_match(hadley, vowels)
vec_in(hadley, vowels)
# Only the first index of duplicates is returned
vec_match(c("a", "b"), c("a", "b", "a", "b"))