CH,
How about any:
any("Tiger" == animal)
The function which will tell you the index if any match
which("Tiger" == animal.
You should also look at the match funciton.
Dave
From:
"C.H." <[email protected]>
To:
R-help <[email protected]>
Date:
12/13/2010 08:50 AM
Subject:
[R] check for item in vector
Sent by:
[email protected]
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.
> func("Tiger",animal) # check for the existence of "Tiger"
TRUE
> func("Acacia",animal) #Acacia is not an item of the animal vector
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
--
CH Chan
______________________________________________
[email protected] 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.
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.