Christoph Heibl
2007-Jan-31 10:00 UTC
[R] Check for presence of object in group of objects
Dear List,
must be simple, but i got stuck on this...
I?ve been trying around for some time, but I could not find a
straigthforward way to do this:
How can one ask if a certain object is element of a certain group of
objects, e.g stored in a vector?
x <- c("a", "b", "c")
# is there a simple function which returns:
is "a" part of x?
TRUE
is "d" part of x?
FALSE
Thanks a lot
Christoph
Christoph Heibl wrote:> Dear List, > > must be simple, but i got stuck on this... > > I?ve been trying around for some time, but I could not find a > straigthforward way to do this: > How can one ask if a certain object is element of a certain group of > objects, e.g stored in a vector? > > x <- c("a", "b", "c") > # is there a simple function which returns: > is "a" part of x? > TRUE > is "d" part of x? > FALSEx <- c("a", "b", "c") "a" %in% x [1] TRUE "d" %in% x [1] FALSE ?is.element> Thanks a lot > Christoph > > ______________________________________________ > R-help at stat.math.ethz.ch 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.-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
ONKELINX, Thierry
2007-Jan-31 10:16 UTC
[R] Check for presence of object in group of objects
You need %in%
"a" %in% x
"d" %in% x
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology
and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be
Do not put your faith in what statistics say until you have carefully considered
what they do not say. ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney
-----Oorspronkelijk bericht-----
Van: r-help-bounces op stat.math.ethz.ch [mailto:r-help-bounces op
stat.math.ethz.ch] Namens Christoph Heibl
Verzonden: woensdag 31 januari 2007 11:01
Aan: r-help op stat.math.ethz.ch
Onderwerp: [R] Check for presence of object in group of objects
Dear List,
must be simple, but i got stuck on this...
I?ve been trying around for some time, but I could not find a
straigthforward way to do this:
How can one ask if a certain object is element of a certain group of
objects, e.g stored in a vector?
x <- c("a", "b", "c")
# is there a simple function which returns:
is "a" part of x?
TRUE
is "d" part of x?
FALSE
Thanks a lot
Christoph
______________________________________________
R-help op stat.math.ethz.ch 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.