[R] multiple match question
Marc Mamin
M.Mamin at intershop.de
Wed Sep 29 18:09:19 CEST 2004
Hello,
I'm looking for a fast way to retrieve the position of elements from a vector which match element in another vector.
Example
va<-c('a','e')
vb<-c('a','b','c','d','e','f','e')
f(va,vb) should return c(1,5,7)
I have 2 different cases:
I) my vector vb contains only distinct values
II) my vector vb may contains the same values more than once.
for I) I use following which is fast enough:
as.vector(na.omit(unlist(lapply(va,match,vb))))
Thanks for any help,
Marc
More information about the R-help
mailing list