Dear all, is there any funktion in R which i can use to check if a single value is element of a matrix or data.frame so that it returns me logical values like TRUE/FALSE. Thanks in advance for your help!
alexander.schnee at tuebingen.mpg.de wrote:> Dear all, > > is there any funktion in R which i can use to check if a single value is > element of a matrix or data.frame so that it returns me logical values > like TRUE/FALSE. > > Thanks in advance for your help!See help("%in%") Uwe Ligges
Do you mean *an* element or *this* element of a matrix? is.element or %in% for the first == for the second. It doesn't really make sense for a data frame, where columns can be of arbitrary classes. I am not sure if I have unscrambled your English correctly: if not a simple example of what you want to do would help. (We don't need examples of logical values, though.) On Wed, 7 May 2003 alexander.schnee at tuebingen.mpg.de wrote:> is there any funktion in R which i can use to check if a single value is > element of a matrix or data.frame so that it returns me logical values > like TRUE/FALSE.(or possibly NA if there are NAs in the matrix?) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
>-----Original Message----- >From: r-help-bounces at stat.math.ethz.ch >[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of >alexander.schnee at tuebingen.mpg.de >Sent: Wednesday, May 07, 2003 10:59 AM >To: r-help at stat.math.ethz.ch >Subject: [R] element of > > >Dear all, > >is there any funktion in R which i can use to check if a >single value is element of a matrix or data.frame so that it >returns me logical values like TRUE/FALSE. > >Thanks in advance for your help!See help("%in%") which will give you a TRUE/FALSE value. You can also use which() to get the actual position of the element in the data structure. See help("which") for more information on that function. HTH, Marc Schwartz
On Wed, May 07, 2003 at 05:59:23PM +0200, alexander.schnee at tuebingen.mpg.de wrote:> is there any funktion in R which i can use to check if a single value is > element of a matrix or data.frame so that it returns me logical values like > TRUE/FALSE.is.element(foo, mymatrix) which is the same as foo %in% mymatrix cu Philipp -- Dr. Philipp Pagel Tel. +49-89-3187-3675 Institute for Bioinformatics / MIPS Fax. +49-89-3187-3585 GSF - National Research Center for Environment and Health Ingolstaedter Landstrasse 1 85764 Neuherberg Germany