[R] How to get intersection of multiple vectors?

ken knoblauch ken.knoblauch at inserm.fr
Thu Feb 2 09:09:30 CET 2012


孟欣 <lm_mengxin <at> 163.com> writes:

> 
> v1<-c("a","b","c","d")
> v2<-c("a","b","e")
> v3<-c("a","f","g")
> 
> I want to get the intersection of v1,v2,v3,ie "a"
> 
> How can I do then?
> 
> What I know is only for 2 vectors via "intersect" function,
but don't know how to 
deal with multiple 
vectors.
> 

Reduce(intersect,  list(v1 = c("a","b","c","d"),
              v2 = c("a","b","e"),
              v3 = c("a","f","g")))

> Many thanks

-- 
Ken Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html



More information about the R-help mailing list