vintersect: Perform intersection of two vectors, including counting...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/vintersect.R

Description

Unlike the base::intersect function, if the vectors have repeated elements in common, the intersection returns as many of these elements as are in whichever vector has fewer of them.

Usage

1
vintersect(x, y, multiple = TRUE)

Arguments

x

A vector or an object which can be coerced to a vector

y

A vector or an object which can be coerced to a vector

multiple

Should repeated "multiple" items be returned? Default is TRUE; if set to FALSE, vintersect acts like the base::intersect function.

Value

A vector of the elements in the intersection of the two vectors. If multiple=FALSE is set, only unique values are returned.

Author(s)

Carl Witthoft, with some code taken from Sven Hohenstein via Stack Overflow

See Also

intersect, the CRAN package sets

Examples

1
2
3
4
5
x <- c(1:5,3,3,3,2,NA,NA)
y<- c(2:5,4,3,NA)
vintersect(x,y)
vintersect(x,y,multiple=FALSE) 
intersect(x,y) #same as previous line

Example output

[1]  2  3  3  4  5 NA
[1]  2  3  4  5 NA
[1]  2  3  4  5 NA

vecsets documentation built on March 8, 2021, 1:13 a.m.