将大型 CSV DTM 转换为 tm 包 DTM

Convert Large CSV DTM to tm package DTM

我有一个很大的 csv 文件 (3.8 Gb),其中包含列(术语)、行(文档)格式的数据。我想将其转换为 tm 包中的 dtm。

我在这里跳过 read.csv 这一步,但你明白了。

dtm <- structure(list(the = c(2L, 1L), apple = c(0L, 2L), dumb = c(1L, 0L)), .Names = c("the", "apple", "dumb"), class = "data.frame", row.names = c(NA, -2L))

然后我不知道如何将其转换为正式的 tm 包 dtm:

c <- Corpus(DataframeSource(dtm))

显然这是错误的。

感谢任何指导。

这样做就可以了:

tmDTM <- tm::as.DocumentTermMatrix(slam::as.simple_triplet_matrix(dtm),
                                   weighting = tm::weightTf)

quanteda 包也对此功能进行了一些很好的实现。