[R] create a pairwise coocurrence matrix
Stefan Evert
stefanML at collocations.de
Thu Nov 11 10:44:31 CET 2010
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
More information about the R-help
mailing list