On Thu, Feb 02, 2012 at 01:55:07PM +0800, 孟欣 wrote:
> 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.
Hi.
Try the following
intersectSeveral <- function(...) { Reduce(intersect, list(...)) }
intersectSeveral(v1, v2, v3)
[1] "a"
Hope this helps.
Petr Savicky.
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.