How about using this double sapply ?
l <- list(a,b,c,d) sapply(seq_len(length(l)), function(x) sapply(seq_len(length(l)), function(y) length(intersect(unlist(l[x]), unlist(l[y]))))) [,1] [,2] [,3] [,4] [1,] 4 0 0 0 [2,] 0 4 1 0 [3,] 0 1 3 0 [4,] 0 0 0 2
Interpretation: for example. the element [1,2] of the matrix shows you how many elements the first element of the list l (in this case, the subscript a ) has in conjunction with the second element of the list (ie, sublist b )
Or, alternatively, just see subscription indexes that have a common meaning with some other sublist:
which(sapply(seq_len(length(l)), function(x) length(intersect(l[[x]], unlist(l[-x])))) >= 1) [1] 2 3
Datamine r
source share