Skip to content

match vs. %in% (PR#853)

2 messages · Jonathan Baron, Brian Ripley

#
This isn't really a bug so much as an undocumented feature, but
perhaps the help file should be changed.

If you say
match(x,y)
you get the values of the _first_ instance in y that matches each
value of x.

If you say 
x %in% y
you get "TRUE" for every match, not just the first.

This is useful, now that I know it, but perhaps the thing
about the first instance should be documented.

I still don't understand why it happens!

Jon

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Sun, 18 Feb 2001 baron@cattell.psych.upenn.edu wrote:

            
Yes, but one match or not for each instance of x.
You get a result for each element of x, not y.

Both return a result for each element of x. match returns the index of the
first match or `nomatch',  %in% returns TRUE or FALSE.

is.element is a synonym of %in% compatible with S, which uses %in% for
something else (nesting in formulae).
Yes, ?match needs a `details' section.  I'll add one.