Hi there, how can I test every element in a vector whether appears in another vector? such as a<-c("aa", "bb", "ff", "cc") b <-c("oo","jj","bb","cc") somefunction(a,b) gives [False, True, False, True] thanks yuan jian [[alternative HTML version deleted]]
Hi Yuan, Try> a<-c("aa", "bb", "ff", "cc") > b <-c("oo","jj","bb","cc") > a %in% b[1] FALSE TRUE FALSE TRUE HTH, Jorge On Tue, May 11, 2010 at 10:31 PM, Yuan Jian <> wrote:> Hi there, > > how can I test every element in a vector whether appears in another vector? > such as > a<-c("aa", "bb", "ff", "cc") > b <-c("oo","jj","bb","cc") > > somefunction(a,b) gives [False, True, False, True] > > thanks > yuan jian > > > > > > [[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. >[[alternative HTML version deleted]]
<jayuan2008 at yahoo.com> wrote:> how can I test every element in a vector whether appears in another vector? > such as > a<-c("aa", "bb", "ff", "cc") > b <-c("oo","jj","bb","cc")a %in% b [1] FALSE TRUE FALSE TRUE
On May 11, 2010, at 10:31 PM, Yuan Jian wrote:> Hi there, > > how can I test every element in a vector whether appears in another > vector? > such as > a<-c("aa", "bb", "ff", "cc") > b <-c("oo","jj","bb","cc") > > somefunction(a,b) gives [False, True, False, True]The other answers probably gave you what you wanted, but you should not leave this exchange thinking that True == TRUE or that False =FALSE in R. -- David Winsemius, MD West Hartford, CT