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:
# R program to illustrate # the use of is.element() function # Vector 1 x1 < - c( 1 , 2 , 3 ) # Vector 2 x2 < - c( 1 : 6 ) # Calling is.element() Function is .element(x1, x2) is .element(x2, x1) |
Output:
[1] TRUE TRUE TRUE [1] TRUE TRUE TRUE FALSE FALSE FALSE
Example 2:
# R program to illustrate # the use of is.element() function # Data frame 1 data_x < - data.frame(x1 = c( 5 , 3 , 7 ), x2 = c( 1 , 4 , 2 )) # Data frame 2 data_y < - data.frame(y1 = c( 2 , 3 , 4 ), y2 = c( 1 , 4 , 2 ), y3 = c( 3 , 4 , 5 )) # Calling is.element() Function is .element(data_x, data_y) is .element(data_y, data_x) |
Output:
[1] FALSE TRUE [1] FALSE TRUE FALSE
Please Login to comment...