Arrange the words of the Document Term Matrix by frequency in R

让人想犯罪 __ 提交于 2019-12-25 08:07:14

问题


i'm sorry for new question , but i newbie in text mining, and need in advices of profy. Now, after long torments with content_transformer i have clean corpus The next question

1. How  select from `dtm`  the words with small frequencies , so that the amount of frequencies was not more than 1%

For example i need this format

x 0,5% of all words in the dataset
y 0,2%
z 0,3%

so here total frequencies sum =1% How do this?


回答1:


You can take a look into the termDocumentMatrix function of the tm package. This contains a way to count the occurrences of the words per document. Adding these numbers over the total corpus should lead you where you want to be.

dtm <- DocumentTermMatrix(corpus)
# wordcounts for complete corpus
counts <- colSums(as.matrix(dtm))

# number of documents
nb <- length(counts)
# frequencies
freqs <- counts / nb


来源:https://stackoverflow.com/questions/42159784/arrange-the-words-of-the-document-term-matrix-by-frequency-in-r

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