r语言 - Rtexttools 使用create_matrix创建文档术语矩阵时遇到问题



我是第一次使用RTextTools。这是我的create_matrix代码

library(RTextTools)
texts <- c("This is the first document.", 
          "Is this a text?", 
        "This is the second file.", 
        "This is the third text.", 
        "File is not this.") 
doc_matrix <- create_matrix(texts, language="english", removeNumbers=FALSE, stemWords=TRUE, removeSparseTerms=.2)

我收到以下错误:

Error in `[.simple_triplet_matrix`(matrix, , sort(colnames(matrix))) : 
Invalid subscript type: NULL.
In addition: Warning messages:
1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
2: In is.na(j) : is.na() applied to non-(list or vector) of type 'NULL'

还没有看到其他人发布此错误,并且认为我缺少一些非常基本的东西。

彼得

您需要删除最后一个参数,removeSparseTerms=.2)tm包文档中removeSparseTerms:"一个术语文档矩阵,其中删除了来自 x 的那些术语,这些术语至少具有稀疏百分比的空(即,术语在文档中出现 0 次)元素。即,生成的矩阵仅包含稀疏因子小于稀疏的项。

我认为稀疏阈值对于您的数据集来说太低了。

doc_matrix <- create_matrix(texts, language="english", removeNumbers=FALSE, stemWords=TRUE, removeSparseTerms=.9999)

最新更新