[R] check for item in vector
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 __ R-help@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.
Re: [R] check for item in vector
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 : 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 -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@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.
Re: [R] check for item in vector
Hi CH, Check ?is.element ?%in% HTH, Jorge On Mon, Dec 13, 2010 at 9:48 AM, C.H. wrote: 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 __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] check for item in vector
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. chainsawti...@gmail.com To: R-help r-help@r-project.org Date: 12/13/2010 08:50 AM Subject: [R] check for item in vector Sent by: r-help-boun...@r-project.org 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 __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.