[R] test if vector contains elements of another vector (disregarding the position)

Martin Batholdy batholdy at googlemail.com
Mon Aug 22 17:51:19 CEST 2011


Hi,


I have the following problem:


I have two vectors:

i <- c('a','c','g','h','b','d','f','k','l','e','i')

j <- c('a', 'b', 'c')



now I would like to generate a vector with the length of i that 
has zeros where i[x] != any element of j 
and 1 where i[x] == any element of j.

So for the example above the vector would look like this:

c(1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0)



can someone help me on this?



More information about the R-help mailing list