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