[R] match multiple records

Jim Brennan jfbrennan at rogers.com
Tue Jun 21 00:50:33 CEST 2005


R>a<-c(1,2,3)
R> b<-c(1,1,2,4)
R>1*b%in%a*b
[1] 1 1 2 0
R> b<-c(1,1,2,4,5,1,2,3,4)
R>1*b%in%a*b
[1] 1 1 2 0 0 1 2 3 0

I think this works

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Weiwei Shi
Sent: June 20, 2005 6:35 PM
To: R-help at stat.math.ethz.ch
Subject: [R] match multiple records

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,

-- 
Weiwei Shi, Ph.D

"Did you always know?"
"No, I did not. But I believed..."
---Matrix III

______________________________________________
R-help at 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




More information about the R-help mailing list