Skip to content
Prev 181961 / 398503 Next

mapply

well, you do not have to compute the pairwise difference each time; for 
instance, you could use something like this (untested):

out1 <- outer(a, c, "-")
out2 <- outer(b, c, "-")

u <- v <- 1:5
mat <- matrix(0, length(u), length(u))
for (i in seq_len(u)) {
     for (j in seq_len(v)) {
         res1 <- colSums(abs(out1 - i) == 0) > 0
         res2 <- colSums(abs(out2 - j) == 0) > 0
         mat[i, j] <- sum(res1 & res2)
     }
}
mat


I hope it helps.

Best,
Dimitris
KARAVASILIS GEORGE wrote: