Learn R Programming

udpipe (version 0.8.3)

dtm_cor: Pearson Correlation for Sparse Matrices

Description

Pearson Correlation for Sparse Matrices. More memory and time-efficient than cor(as.matrix(x)).

Usage

dtm_cor(x)

Arguments

x

A matrix, potentially a sparse matrix such as a "dgTMatrix" object which is returned by document_term_matrix

Value

a correlation matrix

See Also

document_term_matrix

Examples

Run this code
# NOT RUN {
x <- data.frame(
 doc_id = c(1, 1, 2, 3, 4), 
 term = c("A", "C", "Z", "X", "G"), 
 freq = c(1, 5, 7, 10, 0))
dtm <- document_term_matrix(x)
dtm_cor(dtm)
# }

Run the code above in your browser using DataLab