Skip to content
Prev 241204 / 398500 Next

create a pairwise coocurrence matrix

If I understood you correctly, you have this matrix of indicator variables for occurrences of terms in documents:

  A <- matrix(c(1,1,0,0,1,1,1,0,1,1,1,0,0,0,1), nrow=3, byrow=TRUE, dimnames=list(paste("doc",1:3), paste("term",1:5)))
  A

and want to determine co-occurrence counts for pairs of terms, right? (The formatting of your matrices was messed up, and some of your co-occurrence counts don't make sense to me.)

The fastest and easiest solution is

  t(A) %*% A

Hope this helps,
Stefan