Re: [R] One to One Matching multiple vectors

From: Nick Sabbe <nick.sabbe_at_ugent.be>
Date: Wed, 16 Mar 2011 10:49:39 +0100

Hello Vincy.
You probably want
y[match(z,x)]
Or, more instructional:
whereAreZInX<-match(z, x)
y[whereAreZInX]

HTH, Nick Sabbe

--
ping: nick.sabbe_at_ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36

-- Do Not Disapprove




-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On
Behalf Of Vincy Pyne
Sent: woensdag 16 maart 2011 10:42
To: r-help_at_r-project.org
Subject: [R] One to One Matching multiple vectors

Dear R helpers

Suppose,

x = c(0,  1,  2,  3)

y = c("A", "B", "C", "D")

z = c(1, 3)

For given values of z, I need to the values of y. So I should get "B" and
"D". 

I tried doing 

y[x][z] but it gives 


> y[x][z]
[1] "A" "C" Kindly guide. Regards Vincy [[alternative HTML version deleted]] ______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Wed 16 Mar 2011 - 09:52:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Mar 2011 - 10:40:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive