This method sorts an object of class freqlist.
# S3 method for freqlist
sort(
x,
decreasing = FALSE,
sort_crit = c("ranks", "names", "orig_ranks", "freqs"),
na_last = TRUE,
...
)Object of class freqlist.
Object of class freqlist.
Logical. If TRUE items are sorted from large
to small; if FALSE, from small to large.
Note, however, that ranking in frequency lists is such that lower ranks
correspond to higher frequencies. Therefore, sorting by rank (either
"ranks" or "orig_ranks") with decreasing set
to its default value FALSE results in the highest frequencies
ending up at the beginning of the sorted list.
Character string determining the sorting criterion.
If sort_crit is "ranks", then the items in the frequency list
are sorted by their current frequency rank.
If sort_crit is "names", then the items in the frequency
list are sorted alphabetically their name.
If sort_crit is "orig_ranks", then the items in the frequency
list are sorted by their original ranks (if those are present),
or by their current frequency ranks (if no original ranks are present).
Finally, sorting with sort_crit set to "freqs" is identical
to sorting by frequency ranks, but with the meaning of the argument
decreasing being reversed.
In other words, sorting by frequencies ("freqs") with decreasing set
to its default value FALSE results in the lowest frequencies
ending up at the beginning of the sorted list.
Logical defining the behavior of NA elements.
This argument is only relevant when sort_crit is "orig_ranks"
because currently names and frequencies are not allowed to be NA
in frequency lists.
If na_last is TRUE, then items with a sorting criterion of
NA end up at the end of the sorted frequency list.
If na_last is FALSE, then items with a sorting criterion
of NA end up at the start of the sorted frequency list.
If na_last is NA, then items with a sorting criterion of
NA are removed from the sorted frequency list.
Additional arguments.
Because of the way ranks are calculated for ties (with lower ranks being assigned to ties earlier in the list), sorting the list may affect the ranks of ties. More specifically, ranks among ties may differ depending on the criterion that is used to sort the frequency list.
(flist <- freqlist(tokenize("the old story of the old man and the sea.")))
sort(flist)
sort(flist, decreasing = TRUE)
Run the code above in your browser using DataLab