match comebacks a vector of the positions of (very first) matches of its very first argument in its 2nd.
%in% is a more intuitive interface as a binary operator, which comebacks a logical vector indicating if there is a match or not for its left operand.
vector or NULL : the values to be matched. Long vectors are supported.
vector or NULL : the values to be matched against. Long vectors are not supported.
the value to be returned in the case when no match is found. Note that it is coerced to integer .
a vector of values that cannot be matched. Any value in x matching a value in this vector is assigned the nomatch value. For historical reasons, FALSE is equivalent to NULL .
%in% is presently defined as “%in%” <,- function(x, table) match(x, table, nomatch = 0) >, 0
Factors, raw vectors and lists are converted to character vectors, and then x and table are coerced to a common type (the later of the two types in R ‘s ordering, logical <, integer <, numeric <, elaborate <, character) before matching. If incomparables has positive length it is coerced to the common type.
Matching for lists is potentially very slow and best avoided except in plain cases.
Exactly what matches what is to some extent a matter of definition. For all types, NA matches NA and no other value. For real and complicated values, NaN values are regarded as matching any other NaN value, but not matching NA , where for sophisticated x , real and imaginary parts must match both (unless containing at least one NA ).
Character strings will be compared as byte sequences if any input is marked as “bytes” , and otherwise are regarded as equal if they are in different encodings but would agree when translated to UTF-8 (see Encoding ).
That %in% never comebacks NA makes it particularly useful in if conditions.
A vector of the same length as x .
match : An integer vector providing the position in table of the very first match if there is a match, otherwise nomatch .
If x[i] is found to equal table[j] then the value returned in the i -th position of the comeback value is j , for the smallest possible j . If no match is found, the value is nomatch .
%in% : A logical vector, indicating if a match was located for each element of x : thus the values are TRUE or FALSE and never NA .
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The Fresh S Language. Wadsworth &, Brooks/Cole.