What is the is.element() function in R?
Overview
We can check the presence of element(s) of an object in another object using the function is.element() in R language.
Syntax
is.element(x, y)
Syntax for the is.element( ) function in R
Parameter values
The is.element() function takes the following mandatory parameter values:
x: This is the element that we want to search for in an R object.y: This is an R object containing elements.
Return value
The is.element() function returns a logical value (true or false) indicating whether the element appears in y.
Coding example
# creating an R object of elementsA <- c(1, 3, 4, 5, 6, 7, 8)# to check to see if 2 is an element of Ais.element(2, A)
Explanation
In the code above,
- Line 2: We create an R object
Acontaining numerical elements. - Line 5: We check whether the number
2is an element ofAby using theis.element()function.