-->

Removing Words from word cloud in R

2019-07-21 12:51发布

问题:

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]


标签: r word-cloud