View source: R/get_cooccurrence.R
get_cooccurrence | R Documentation |
Get the co-occurrence of column elements per row entity (e.g. document co-occurrence of terms)
get_cooccurrence(m, binarize = TRUE, threshold = 1)
binarize |
By default |
threshold |
Threshold for binarization. By default |
x |
A matrix object (with a document term matrix containing integer counts in mind). Currently accepts base::matrix, Matrix::sparseMatrix or slam::simple_triplet_matrix. |
A sparseMatrix
with the summed (document) co-occurrence per row of the specified column elements (words) of x
.
mat <- cbind(A = c(2,1,1,0), B = c(2,0,1,0), C = c(0,1,1,0)) # A B C D # [1,] 2 2 0 0 # [2,] 1 0 1 0 # [3,] 1 1 1 0 # [4,] 0 0 0 0 get_cooccurrence(mat) # A B C # A 3 2 2 # B 2 2 1 # C 2 1 2 get_cooccurrence(mat, binarize = FALSE) # A B C # A 6 5 2 <- note the difference regarding A and B # B 5 5 1 # C 2 1 2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.