What is the intersect() function in R?
Overview
The intersect() function in R determines the intersection of the subsets of a probability space. For example, intersect(A, B) returns the rows that are common to the subsets A and B.
Syntax
intersect(x, y, ...)
Syntax for the intersect() function in R
Parameter value
The intersect() function takes the following parameter values:
x,y: These are the data frame, or vector, objects that contain a sequence of elements. These are required values....: This represents further arguments that are passed to or from other R methods. This is an optional value.
Return value
The intersect() function returns a vector, data frame, or a probability subset with the same data type as the input argument.
Code example
# Creating subsetsset_A = c('the', 'foo', 'the', 'bar', 'and', 'the', 'baz')set_B = c('The', 'Foo', 'the', 'Bar', 'and', 'the', 'Baz')# Implementing the intersect() functionintersect(set_A, set_B)
Code explanation
- Lines 2–3: We create subsets
set_Aandset_B.
- Line 6: We obtain the intersection of the subsets using the
intersect()function.