Re: [R] match multiple records

From: Marc Schwartz <MSchwartz_at_mn.rr.com>
Date: Tue 21 Jun 2005 - 08:45:59 EST

On Mon, 2005-06-20 at 17:34 -0500, Weiwei Shi wrote:
> Hi,
>
> I have a question, explained by the following example:
> > a<-c(1,2,3)
> > b<-c(1,1,2,4)
> > b[match(a,b, nomatch=0)]
> [1] 1 2
>
> which means it returns "the first match", but I want to get
> 1 1 2 instead of 1 2
>
> In a word, how to do multiple matching?
>
> thanks,

> b[b %in% a]

[1] 1 1 2

See ?"%in%" for more information.

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 21 08:52:27 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:54 EST