Say I have 5 vectors:
a <- c(1,2,3)
b <- c(2,3,4)
c <- c(1,2,5,8)
d <- c(2,3,4,6)
e <- c(2,7,8,9)
I know I can calculate the intersection between all of them by using Reduce()
together with intersect()
, like this:
Reduce(intersect, list(a, b, c, d, e))
[1] 2
But how can I find elements that are common in, say, at least 2 vectors? i.e.:
[1] 1 2 3 4 8