问题
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