Creating a subset of words from a corpus in R

自闭症网瘾萝莉.ら 提交于 2019-12-05 16:43:18

You can convert your tdm object into a matrix and work with that to get something that wordcloud can work with:

library(tm)
library(wordcloud)
# example data from the tm package
data(crude)
tdm <- TermDocumentMatrix(crude,
                      control = list(removePunctuation = TRUE,
                                     stopwords = TRUE))
v <- rowSums(as.matrix(tdm))
names(v) <- rownames(as.matrix(tdm))
v <- sort(v, decreasing=T)

Now with this you can filter out infrequent words with standard subsetting ([), or you can use the min.freq argument to wordcloud when you want to plot:

wordcloud(names(v), v, min.freq=10, scale=c(10,.3))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!