function in R Language is used to find the intersection of two Objects. This function takes two objects like Vectors, dataframes, etc. as arguments and results in a third object with the common data of both the objects.**intersect()**

Syntax:intersect(x, y)

Parameters:

x and y:Objects with sequence of items

**Example 1:**

`# R program to illustrate ` `# intersection of two vectors ` ` ` `# Vector 1 ` `x1 <` `-` `c(` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `5` `, ` `6` `, ` `5` `, ` `5` `) ` ` ` `# Vector 2 ` `x2 <` `-` `c(` `2` `:` `4` `) ` ` ` `# Intersection of two vectors ` `x3 <` `-` `intersect(x1, x2) ` ` ` `print` `(x3) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 2 3 4

**Example 2:**

`# R program to illustrate ` `# the intersection of two data frames ` ` ` `# Data frame 1 ` `data_x <` `-` `data.frame(x1 ` `=` `c(` `2` `, ` `3` `, ` `4` `), ` ` ` `x2 ` `=` `c(` `1` `, ` `1` `, ` `1` `)) ` ` ` `# Data frame 2 ` `data_y <` `-` `data.frame(y1 ` `=` `c(` `2` `, ` `3` `, ` `4` `), ` ` ` `y2 ` `=` `c(` `2` `, ` `2` `, ` `2` `)) ` ` ` `# Intersection of two data frames ` `data_z <` `-` `intersect(data_x, data_y) ` ` ` `print` `(data_z) ` |

*chevron_right*

*filter_none*

**Output:**

y1 1 2 2 3 3 4

## Recommended Posts:

- Get Exclusive Elements between Two Objects in R Programming - setdiff() Function
- Check if Two Objects are Equal in R Programming - setequal() Function
- Union of two Objects in R Programming - union() Function
- Check for Presence of Common Elements between Objects in R Programming - is.element() Function
- Get Addition of the Objects passed as Arguments in R Programming - sum() Function
- Concatenating Objects in R Programming - combine() Function
- List all the Objects present in the Current Working Directory in R Programming - ls() Function
- Remove Objects from Memory in R Programming - rm() Function
- Looping over Objects in R Programming
- Compare two Objects for Equality in R Progamming - identical() Function
- Getting attributes of Objects in R Language - attributes() and attr() Function
- Getting Multiplication of the Objects passed as Arguments in R Language - prod() Function
- Check if a Function is a Primitive Function in R Programming - is.primitive() Function
- R - Objects
- R - Creating, Listing, and Deleting Objects in Memory
- Performing different Operations on Two Arrays in R Programming - outer() Function
- Compute the Covariance between Two Vectors in R Programming - cov() Function
- Compute the Correlation Coefficient Value between Two Vectors in R Programming - cor() Function
- Merge Two Data Frames by common Columns in R Programming - merge() Function
- Add Color Between Two Points of Kernel Density Plot in R Programming - Using with() Function

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.