This method sorts an object of class freqlist.
Arguments
- x
Object of class
freqlist.- decreasing
Logical. If
TRUEitems are sorted from large to small; ifFALSE, 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") withdecreasingset to its default valueFALSEresults in the highest frequencies ending up at the beginning of the sorted list.- sort_crit
Character string determining the sorting criterion.
If
sort_critis"ranks", then the items in the frequency list are sorted by their current frequency rank.If
sort_critis"names", then the items in the frequency list are sorted alphabetically their name.If
sort_critis"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_critset to"freqs"is identical to sorting by frequency ranks, but with the meaning of the argumentdecreasingbeing reversed. In other words, sorting by frequencies ("freqs") withdecreasingset to its default valueFALSEresults in the lowest frequencies ending up at the beginning of the sorted list.- na_last
Logical defining the behavior of
NAelements.This argument is only relevant when
sort_critis"orig_ranks"because currently names and frequencies are not allowed to beNAin frequency lists.If
na_lastisTRUE, then items with a sorting criterion ofNAend up at the end of the sorted frequency list. Ifna_lastisFALSE, then items with a sorting criterion ofNAend up at the start of the sorted frequency list. Ifna_lastisNA, then items with a sorting criterion ofNAare removed from the sorted frequency list.- ...
Additional arguments.
Value
Object of class freqlist.
Details
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.
Examples
(flist <- freqlist(tokenize("the old story of the old man and the sea.")))
#> Frequency list (types in list: 7, tokens in list: 10)
#> rank type abs_freq nrm_freq
#> ---- ----- -------- --------
#> 1 the 3 3000
#> 2 old 2 2000
#> 3 and 1 1000
#> 4 man 1 1000
#> 5 of 1 1000
#> 6 sea 1 1000
#> 7 story 1 1000
sort(flist)
#> Frequency list (types in list: 7, tokens in list: 10)
#> rank orig_rank type abs_freq nrm_freq
#> ---- --------- ----- -------- --------
#> 1 1 the 3 3000
#> 2 2 old 2 2000
#> 3 3 and 1 1000
#> 4 4 man 1 1000
#> 5 5 of 1 1000
#> 6 6 sea 1 1000
#> 7 7 story 1 1000
sort(flist, decreasing = TRUE)
#> Frequency list (types in list: 7, tokens in list: 10)
#> rank orig_rank type abs_freq nrm_freq
#> ---- --------- ----- -------- --------
#> 7 7 story 1 1000
#> 6 6 sea 1 1000
#> 5 5 of 1 1000
#> 4 4 man 1 1000
#> 3 3 and 1 1000
#> 2 2 old 2 2000
#> 1 1 the 3 3000
