ranks
retrieves from the ranks of its items in an object.
These ranks are integer values running from one up to the number of items
in x
. Each items receives a unique rank.
Items are first ranked by frequency in descending order. Items with
identical frequency are further ranked by alphabetic order.
Arguments
- x
An object of any of the classes for which the method is implemented.
- ...
Additional arguments.
- with_names
Logical. Whether or not the items in the output should be given names. If
TRUE
, then the names of the types in the frequency list are used as names.
Value
Numeric vector representing the current ranks, with as its names the types to which the ranks apply.
Details
The mclm method ranks()
is not
to be confused with base::rank()
. There are two
important differences.
First,base::rank()
always ranks items from low values to
high values and ranks()
ranks from high
frequency items to low frequency items.
Second, base::rank()
allows the user to choose among
a number of different ways to handle ties.
In contrast, ranks()
always handles ties
in the same way. More specifically, items with identical frequencies
are always ranked in alphabetical order.
In other words, base::rank()
is a flexible tool that
supports a number of different ranking methods that are commonly used in
statistics. In contrast, ranks()
is a
rigid tool that supports only one type of ranking, which is a type of
ranking that is atypical from a statistics point of view, but is commonly
used in linguistic frequency lists. Also, it is designed to be unaffected
by the order of the items in the frequency list.
See also
Other getters and setters:
n_tokens()
,
n_types()
,
orig_ranks()
,
tot_n_tokens()
,
type_names()
Examples
(flist <- freqlist("The man and the mouse.", as_text = TRUE))
#> Frequency list (types in list: 4, tokens in list: 5)
#> rank type abs_freq nrm_freq
#> ---- ----- -------- --------
#> 1 the 2 4000
#> 2 and 1 2000
#> 3 man 1 2000
#> 4 mouse 1 2000
orig_ranks(flist)
#> NULL
ranks(flist)
#> [1] 1 2 3 4
ranks(flist, with_names = TRUE)
#> the and man mouse
#> 1 2 3 4
(flist2 <- keep_types(flist, c("man", "and")))
#> Frequency list (types in list: 2, tokens in list: 2)
#> <total number of tokens: 5>
#> rank orig_rank type abs_freq nrm_freq
#> ---- --------- ---- -------- --------
#> 2 3 man 1 2000
#> 1 2 and 1 2000
orig_ranks(flist2)
#> [1] 3 2
ranks(flist2)
#> [1] 2 1