我想绘制一个术语文档矩阵,如图6所示,位于JSS article on TM包1文章链接:https://www.jstatsoft.org/article/view/v025i05中
我的语料库Speach-English.txt在这里:https://github.com/yushu-liu/speach-english.git
该图应如下所示:

下面是我的代码:
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出来了:
Error in UseMethod("TermDocumentMatrix", x) :
no applicable method for 'TermDocumentMatrix' applied to an object of class "character"为什么?谢谢!
https://stackoverflow.com/questions/47709910
复制相似问题