Sorts a dfm by descending frequency of total features, total features in documents, or both.

dfm_sort(x, decreasing = TRUE, margin = c("features", "documents", "both"))

Arguments

x

Document-feature matrix created by dfm

decreasing

logical; if TRUE, the sort will be in descending order, otherwise sort in increasing order

margin

which margin to sort on features to sort by frequency of features, documents to sort by total feature counts in documents, and both to sort by both

Value

A sorted dfm matrix object

Examples

dtm <- dfm(data_corpus_inaugural) head(dtm)
#> Document-feature matrix of: 6 documents, 9,357 features (93.8% sparse).
head(dfm_sort(dtm))
#> Document-feature matrix of: 6 documents, 9,357 features (93.8% sparse).
head(dfm_sort(dtm, decreasing = FALSE, "both"))
#> Document-feature matrix of: 6 documents, 9,357 features (96.3% sparse).