VOOZH about

URL: https://www.geeksforgeeks.org/r-language/intersection-of-two-objects-in-r-programming-intersect-function/

⇱ Intersection of Two Objects in R Programming - intersect() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Intersection of Two Objects in R Programming - intersect() Function

Last Updated : 15 Jul, 2025

In this article, we will discuss how we do the Intersection of Two Objects in R Programming Language using the intersect() function.

What is the intersect() Function?

intersect() function in R Programming 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 objects.

Syntax: intersect(x, y)

Parameters:x and y: Objects with the sequence of items

Example 1: the intersection of two vectors

Output:

[1] 2 3 4

Example 2: intersect() function with character vectors

Output:

[1] "C" "D" "E" "F"

Example 3: The intersection of two data frames

Output:

$x1
[1] 2 3 4

Example 4: The intersection of two Matrix

Output:

 [,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9 [,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12[1] 1 2 3 4 5 6 7 8 9
Comment

Explore