[R] intersect of list elements

From: Georg Otto <georg.otto_at_tuebingen.mpg.de>
Date: Sat 22 Jul 2006 - 03:39:09 EST


i have a list of several vectors, for example:

> vectorlist

[1] "a" "b" "c"

[1] "a" "b" "d"

[1] "e" "f" "g"

I can use intersect to find elements that appear in $vector.a.1 and $vector.a.2:

> intersect(vectorlist[[1]], vectorlist[[2]])
[1] "a" "b"

I would like to use grep to get the vectors by their names matching an expression and to find the intersects between those vectors. For the first step:

> vectorlist[grep ("vector.a", names(vectorlist))]
[1] "a" "b" "c"

[1] "a" "b" "d"

Unfortunately, I can not pass the two vectors as argument to intersect:

> intersect(vectorlist[grep ("vector.a", names(vectorlist))])
Error in unique(y[match(x, y, 0)]) : argument "y" is missing, with no default

I am running R Version 2.3.1 (2006-06-01)

Could somone help me to solve this?



R-help@stat.math.ethz.ch 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. Received on Sat Jul 22 03:42:39 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 22 Jul 2006 - 06:15:21 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.