[R] One to One Matching multiple vectors

Erich Neuwirth erich.neuwirth at univie.ac.at
Wed Mar 16 11:22:48 CET 2011


y[which(x %in% z)]

On 3/16/2011 10:42 AM, Vincy Pyne wrote:
> 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.



More information about the R-help mailing list