[R] One to One Matching multiple vectors
Nick Sabbe
nick.sabbe at ugent.be
Wed Mar 16 10:49:39 CET 2011
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]]
More information about the R-help
mailing list