search for: common_elements

Displaying 1 result from an estimated 1 matches for "common_elements".

2011 Nov 04
1
Counting number of common elements between the rows of two different matrices
...1: 1 # (8 is a common element) A1 vs B2: 1 # (8 is a common element) A2 vs B1: 1 # (2 is a common element) A2 vs B2: 1 # 11, 13 are common elements Etc. I've built a function that counts the number of common elements between two vectors, based on the intersect function in the R manual common_elements <- function(x,y) length(y[match(x,y,nomatch=0)]) And a double loop who solves my problem would be something like (pseudo-code) For(i in 1:N_A){ for(j in 1:N_B){ ce(i,j)=common_elements(a(i),b(j)) } } Is there an efficient, clean way to do the same job and give as an output a matrix N_A...