我正在尝试使用R中TermDocumentMatrix
包的tm
函数制作术语 - 文档矩阵,并发现某些字词未包含在内。
> library(tm)
> tdm <- TermDocumentMatrix(Corpus(VectorSource("The book is of great importance.")))
> rownames(tdm)
[1] "book" "great" "importance." "the"
此处, 和 已从矩阵中排除。如果语料库仅包含已删除的单词,则会显示以下消息。
> tdm <- TermDocumentMatrix(Corpus(VectorSource("of is of is")))
Warning message:
In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
> rownames(tdm)
NULL
和 的消息信号在构建矩阵之前被删除,但我无法弄清楚它为什么会出现以及如何包含所有语料库中的令牌。
感谢任何帮助。
答案 0 :(得分:3)
使用TermDocumentMatrix的控制参数
require(tm)
tdm <- TermDocumentMatrix(Corpus(VectorSource("of is of is")), control = list(stopwords=FALSE, wordLengths=c(0, Inf)))
rownames(tdm)