小编dja*_*216的帖子

R错误:inherits(x,c("DocumentTermMatrix","TermDocumentMatrix"))不是TRUE

我正在使用以下代码创建文档术语矩阵.我创建矩阵没有问题,但当我尝试删除稀疏术语或查找常用术语时,我收到错误.

text<- c("Since I love to travel, this is what I rely on every time.", 
         "I got this card for the no international transaction fee", 
         "I got this card mainly for the flight perks",
         "Very good card, easy application process",
         "The customer service is outstanding!") 

library(tm)
corpus<- Corpus(VectorSource(text))
corpus<- tm_map(corpus, content_transformer(tolower))
corpus<- tm_map(corpus, removePunctuation)
corpus<- tm_map(corpus, removeWords, stopwords("english"))
corpus<- tm_map(corpus, stripWhitespace)

dtm<- as.matrix(DocumentTermMatrix(corpus))
Run Code Online (Sandbox Code Playgroud)

结果如下:

Docs    application card    customer    easy    every ... etc.
1       0           0       0           1       0
2       0 …
Run Code Online (Sandbox Code Playgroud)

nlp r text-analysis tm

0
推荐指数
1
解决办法
1373
查看次数

标签 统计

nlp ×1

r ×1

text-analysis ×1

tm ×1