Hi, I have a integer vector x that contains a unique set of numbers: x <- c(1,2,4,6,8,10,12) Is there a simple test I can use to determine if an integer such as 6 is contained in x ? Thanks in advance for any help, Arend
r-help-bounces at stat.math.ethz.ch wrote on 30/04/2004 15:33:48:> Hi, > > I have a integer vector x that contains a unique set of numbers: > > x <- c(1,2,4,6,8,10,12) > > Is there a simple test I can use to determine if an integer such as 6 is > contained in x ?> x <- c(1,2,4,6,8,10,12) > 6 %in% x[1] TRUE See ?"%in%" and its 'See also:' section. HTH, Tobias
On 30 Apr 2004 at 9:33, Arend P. van der Veen wrote:> x <- c(1,2,4,6,8,10,12) > 6 %in% x[1] TRUE>Kjetil Halvorsen> Hi, > > I have a integer vector x that contains a unique set of numbers: > > x <- c(1,2,4,6,8,10,12) > > Is there a simple test I can use to determine if an integer such as 6 > is contained in x ? > > Thanks in advance for any help, > Arend > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
Arend P. van der Veen wrote:> Hi, > > I have a integer vector x that contains a unique set of numbers: > > x <- c(1,2,4,6,8,10,12) > > Is there a simple test I can use to determine if an integer such as 6 is > contained in x ?Try the following and experiment: x %in% c(2,4) which(x %in% c(2,4)) x[which(x %in% c(2,4)) ] 1. logical vector w/ TRUE's where one of the c(2,4) are located, F's otherwise 2. indexes of the TRUE's generated above 3. the vector subset from those indexes Sorry to be so terse, but that might help> > Thanks in advance for any help, > Arend > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >