首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TM包: UseMethod("TermDocumentMatrix",x)出错

TM包: UseMethod("TermDocumentMatrix",x)出错
EN

Stack Overflow用户
提问于 2017-12-08 15:50:12
回答 0查看 3.2K关注 0票数 0

我想绘制一个术语文档矩阵,如图6所示,位于JSS article on TM包1文章链接:https://www.jstatsoft.org/article/view/v025i05

我的语料库Speach-English.txt在这里:https://github.com/yushu-liu/speach-english.git

该图应如下所示:

下面是我的代码:

代码语言:javascript
复制
library(tm)
library(stringr)
library(wordcloud)

text <- paste(readLines("D:/Rdata/speach-English.txt"), collapse = " ")
text_tidy <- gsub(pattern = "\\W",replace=" ",text)
text_tidy2 <- gsub(pattern = "\\d",replace=" ",text_tidy)

text_tidy2 <- tolower(text_tidy2)
text_tidy2 <- removeWords(text_tidy2,stopwords())
text_tidy2 <- gsub(pattern = "\\b[A-z]\\b{1}",replace=" ", text_tidy2 )
text_tidy2 <- stripWhitespace(text_tidy2)

textbag <- str_split(text_tidy2,pattern = "\\s+")
textbag <- unlist(textbag)

tdm <- TermDocumentMatrix(textbag, control = list(removePunctuation = TRUE,
                                                removeNumbers = TRUE,
                                                stopwords = TRUE))

plot(tdm, terms = findFreqTerms(tdm, lowfreq = 6)[1:25], corThreshold = 0.5)

但是有一个bug出来了:

代码语言:javascript
复制
Error in UseMethod("TermDocumentMatrix", x) : 
  no applicable method for 'TermDocumentMatrix' applied to an object of class "character"

为什么?谢谢!

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47709910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档