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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

[1] TRUE TRUE TRUE
[1]  TRUE  TRUE  TRUE FALSE FALSE FALSE

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

[1] FALSE  TRUE
[1] FALSE  TRUE FALSE



My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.