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: 58 documents, 9,357 features (91.8% sparse). #> (showing first 6 documents and first 6 features) #> features #> docs fellow-citizens of the senate and house #> 1789-Washington 1 71 116 1 48 2 #> 1793-Washington 0 11 13 0 2 0 #> 1797-Adams 3 140 163 1 130 0 #> 1801-Jefferson 2 104 130 0 81 0 #> 1805-Jefferson 0 101 143 0 93 0 #> 1809-Madison 1 69 104 0 43 0
head(dfm_sort(dtm))
#> Error in get(".SigLength", envir = env): object '.SigLength' not found
head(dfm_sort(dtm, decreasing = FALSE, "both"))
#> Error in get(".SigLength", envir = env): object '.SigLength' not found