Learn R Programming

clinical (version 0.1)

intersect: Intersection of Multiple Vectors

Description

Returns the intersection of all vectors provided as arguments.

Usage

intersect(x, y, ...)

Value

A character vector (or NULL if no intersection exists) containing the elements that are common to all input vectors.

Arguments

x

A vector.

y

A vector.

...

Additional vectors to include in the intersection.

Author

Stefano Cacciatore

Details

This function computes the intersection of two or more vectors by identifying elements that are present in all of them. Unlike the base R intersect, which only compares two vectors, this version can take multiple vectors as input.

See Also

Examples

Run this code
x <- c("a", "b", "c")
y <- c("b", "c", "d")
z <- c("c", "b", "e")

intersect(x, y, z)  # Returns "b" and "c"
intersect(x, y, c("f", "g"))  # Returns NULL

Run the code above in your browser using DataLab