所以我有一个非常大的术语-文档矩阵:
> class(ph.DTM)
[1] "TermDocumentMatrix" "simple_triplet_matrix"
> ph.DTM
A term-document matrix (109996 terms, 262811 documents)
Non-/sparse entries: 3705693/28904453063
Sparsity : 100%
Maximal term length: 191
Weighting : term frequency (tf)
我该如何获取每个术语的行总和(频率)?我尝试过:
> apply(ph.DTM, 1, sum)
Error in vector(typeof(x$v), nr * nc) : vector size cannot be NA
In addition: Warning message:
In nr * nc : NAs produced by integer overflow
显然,我知道 removeSparseTerms
是什么:
ph.DTM2 <- removeSparseTerms(ph.DTM, 0.99999)
这会稍微减小一点尺寸:
> ph.DTM2
A term-document matrix (28842 terms, 262811 documents)
Non-/sparse entries: 3612620/7576382242
Sparsity : 100%
Maximal term length: 24
Weighting : term frequency (tf)
但是我仍然不能对它应用任何与矩阵相关的函数:
> as.matrix(ph.DTM2)
Error in vector(typeof(x$v), nr * nc) : vector size cannot be NA
In addition: Warning message:
In nr * nc : NAs produced by integer overflow
如何在这个对象上只获取一个简单的行求和?谢谢!
row_sums
函数,似乎比较快。 - bskaggs