I have 2 Document term matrices:
So basically I want to compa
Here is a way to calculate the cosine distance between two matrices. The use of tm is just for data purposes...
library(slam)
library(tm)
data("acq")
data("crude")
dtm <- DocumentTermMatrix(c(acq, crude))
index <- sample(1:70, size = 10)
dtm1 <- dtm[index, ]
dtm2 <- dtm[-index, ]
cosine_sim <- tcrossprod_simple_triplet_matrix(dtm1, dtm2)/sqrt(row_sums(dtm1^2) %*% t(row_sums(dtm2^2)))
The cosine function was adapted from this SO post: R: Calculate cosine distance from a term-document matrix with tm and proxy