Learn R Programming

quanteda (version 0.9.7-17)

sort.dfm: sort a dfm by one or more margins

Description

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

Usage

"sort"(x, decreasing = TRUE, margin = c("features", "docs", "both"), ...)

Arguments

x
Document-feature matrix created by dfm
decreasing
TRUE (default) if sort will be in descending order, otherwise sort in increasing order
margin
which margin to sort on features to sort by frequency of features, docs to sort by total feature counts in documents, and both to sort by both
...
additional arguments passed to base method sort.int

Value

A sorted dfm matrix object

Examples

Run this code
dtm <- dfm(inaugCorpus)
dtm[1:10, 1:5]
dtm <- sort(dtm)
sort(dtm)[1:10, 1:5]
sort(dtm, TRUE, "both")[1:10, 1:5]  # note that the decreasing=TRUE argument
                                    # must be second, because of the order of the
                                    # formals in the generic method of sort()

Run the code above in your browser using DataLab