Removing Words from word cloud in R

别等时光非礼了梦想. 提交于 2020-01-24 17:17:05

问题


I am able to make word cloud, but my problem is when I take the frequency of word counts, I get words whose frequency is 1. I want words whose frequency is greater than 2. How can I do that?

tdm is just a term matrix. I tried with something like rowSums(m>2), but its not working

# define tdm as matrix
m = as.matrix(tdm)
# get word counts in decreasing order
word_freqs = sort(rowSums(m), decreasing=TRUE) 
# create a data frame with words and their frequencies
dm = data.frame(word=names(word_freqs), freq=word_freqs)

Trying to make from https://sites.google.com/site/miningtwitter/questions/talking-about/wordclouds/wordcloud1


回答1:


You could simply filter word_freqs before constructing the data.frame:

word_freqs <- word_freqs[word_freqs > 2]


来源:https://stackoverflow.com/questions/20111432/removing-words-from-word-cloud-in-r

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