2013-11-21 55 views
2

我能够制作单词云,但是我的问题是当我记录单词数量的频率时,我得到的单词频率是1.我想要单词的频率大于2。我可以这样做吗?从R中的文字云中删除单词

tdm只是一个术语矩阵。我试过的东西像rowSums(m>2),但其没有工作

# 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) 

试图从https://sites.google.com/site/miningtwitter/questions/talking-about/wordclouds/wordcloud1

+1

这里看看: http://groupspaces.com/KCRUsersGroup/wiki/wordcloud –

回答

2

,使你可以简单地过滤word_freqs构建data.frame前:

word_freqs <- word_freqs[word_freqs > 2] 
+0

太棒了..感谢.. @ Manetheran..can你告诉我一件事,如果我只想要前两个单词,那我该如何计算它? –

+1

既然你已经有了降序排序的单词,你可以只用前两个元素:'word_freqs < - word_freqs [1:2]'。 –

+0

甚至只是'dm [1:2,]' –