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 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.