我TermDocument
在 R 中使用了 Matrix,并且文档(字符串)也包括单字母单词。使用TermDocument
Matrix 后,术语不包含那些单字母单词,请建议我应该包含哪个控件作为输入参数,以便在我的术语文档矩阵中包含单字母单词。`
问问题
45 次
1 回答
0
默认情况下min wordlength
是3
. 您需要指定参数control
以覆盖默认值,请查看以下代码。
library(tm)
docs <- c("This is a text","When Will u start", "1 12 123")
corpus <- Corpus(VectorSource(docs))
as.matrix(DocumentTermMatrix(corpus)) #words with length < 3 ('a','u','1','12') are excluded
# Terms
#Docs 123 start text this when will
# 1 0 0 1 1 0 0
# 2 0 1 0 0 1 1
# 3 1 0 0 0 0 0
as.matrix(DocumentTermMatrix(corpus, control = list(wordLengths=c(1,Inf))))
# Terms
#Docs 1 12 123 a is start text this u when will
# 1 0 0 0 1 1 0 1 1 0 0 0
# 2 0 0 0 0 0 1 0 0 1 1 1
# 3 1 1 1 0 0 0 0 0 0 0 0
于 2017-03-12T07:12:26.660 回答