Skip to content

element of

5 messages · alexander.schnee@tuebingen.mpg.de, Uwe Ligges, Brian Ripley +2 more

#
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:
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:

            
(or possibly NA if there are NAs in the matrix?)
#
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.element(foo, mymatrix) 

which is the same as 

foo %in% mymatrix


cu
	Philipp