[R] Pairwise intersect comparisons of list elements

Stefan Th. Gries stgries at gmail.com
Fri Nov 21 01:15:20 CET 2008


Hi all

I have two lists that have the same number of numeric vectors such as:
q<-list(1, 2:3, 4:6, 7:10)
w<-list(0, 1:2, 3:7, 8:10)

What I want to do is create a vector desired.result that looks like
this but I am thinking there must be some kind of non-loop /
"\\wapply" way to so ...

desired.result<-numeric()
for (i in 1:4) desired.result[i]<-length(intersect(q[[i]], w[[i]]))
desired.result

Any ideas? Thx,
STG



More information about the R-help mailing list