Skip to content

Intersection of more than two groups in one function?

2 messages · Ken Termiso, Bert Gunter

#
Hi all,

As far as I can tell, the only canned way to do an intersect between two 
vectors of ints is the intersect(vec1, vec2) function -- is there another 
function I'm missing for intersecting more than two vectors??

TIA,
Ken
#
No, I know of no "canned" way to do it, as it's based on match(), which is
for two vectors only.

A brute force loop to do it is simple, as I suspect you realize. Perhaps a
faster way is to use tabulate() to find values that appear n times (for n
vectors). That is:

## assume your integer vectors are components of a list, mylist.

## warning: not tested
bigvec<-unlist(mylist)
sort(unique(bigvec))[tabulate(bigvec)==length(mylist)]



-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box