Check for Presence of Common Elements between Objects in R Programming – is.element() Function
is.element()
function in R Language is used to check if elements of first Objects are present in second Object or not. It returns TRUE for each equal value.
Syntax: is.element(x, y)
Parameters:
x and y: Objects with sequence of items
Example 1:
x1 < - c( 1 , 2 , 3 )
x2 < - c( 1 : 6 )
is .element(x1, x2)
is .element(x2, x1)
|
Output:
[1] TRUE TRUE TRUE
[1] TRUE TRUE TRUE FALSE FALSE FALSE
Example 2:
data_x < - data.frame(x1 = c( 5 , 3 , 7 ),
x2 = c( 1 , 4 , 2 ))
data_y < - data.frame(y1 = c( 2 , 3 , 4 ),
y2 = c( 1 , 4 , 2 ),
y3 = c( 3 , 4 , 5 ))
is .element(data_x, data_y)
is .element(data_y, data_x)
|
Output:
[1] FALSE TRUE
[1] FALSE TRUE FALSE
Last Updated :
15 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...