# NOT RUN {
(myDfm <- dfm(data_corpus_inaugural[1:5]))
# keep only words occurring >=10 times and in >=2 documents
dfm_trim(myDfm, min_count = 10, min_docfreq = 2)
# keep only words occurring >=10 times and in at least 0.4 of the documents
dfm_trim(myDfm, min_count = 10, min_docfreq = 0.4)
# keep only words occurring <=10 times and in <=2 documents
dfm_trim(myDfm, max_count = 10, max_docfreq = 2)
# keep only words occurring <=10 times and in at most 3/4 of the documents
dfm_trim(myDfm, max_count = 10, max_docfreq = 0.75)
# keep only words occurring frequently (top 20%) and in <=2 documents
dfm_trim(myDfm, min_count = 0.8, max_docfreq = 2)
# keep only words occurring 5 times in 1000, and in 2 of 5 of documents
dfm_trim(myDfm, min_docfreq = 0.4, min_count = 0.005)
# }
# NOT RUN {
# compare to removeSparseTerms from the tm package
(myDfmTM <- convert(myDfm, "tm"))
tm::removeSparseTerms(myDfmTM, 0.7)
dfm_trim(myDfm, min_docfreq = 0.3)
dfm_trim(myDfm, sparsity = 0.7)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab