Skip to content

check for item in vector

4 messages · C.H., Ivan Calandra, Jorge Ivan Velez +1 more

#
Dear R users,

Suppose I have an vector like this:

animal <- c("Tiger","Panda")

I would like to know is there any function that check for the
existence of certain item in a vector.

e.g.
TRUE
FALSE

I know that it can be done by for loop. But I would like to know is
there any built-in function for that.

Thank you very much.

CH
#
Hi,

See ?"%in%" or ?match

animal <- c("Tiger","Panda")
"Tiger" %in% animal
[1] TRUE
"Acacia" %in% animal
[1] FALSE
"Panda" %in% animal
[1] TRUE

HTH,
Ivan

Le 12/13/2010 15:48, C.H. a ?crit :