Skip to contents

type_freq and type_freqs retrieve the frequency of all or some of the items of a freqlist object.

Usage

type_freqs(x, types = NULL, with_names = FALSE, ...)

type_freq(x, types = NULL, with_names = FALSE, ...)

Arguments

x

Object of class freqlist.

types

NULL or a character vector or an object of the class types.

If the argument types is NULL, then the frequencies of all the items in x are returned, in the order in which these items appear in x.

If the argument types is a character vector or an object of the class types, then only the frequencies (in x) of the items in types are given, in the order in which these items appear in types. For all items in types that do not occur in x, a frequency of zero is returned.

with_names

Logical. Whether or not the items in the output should be given names. If with_names is TRUE, then the names of the types in the frequency list are used as names.

...

Additional arguments.

Value

Numeric vector representing the frequencies of the items.

See also

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

type_freqs(flist) # frequencies of all items
#> [1] 2 1 1 1
type_names(flist) # names of all items
#> [1] "the"   "and"   "man"   "mouse"

type_freqs(flist, with_names = TRUE) # frequencies of all types, with names
#>   the   and   man mouse 
#>     2     1     1     1 
type_freqs(flist, c("man", "the")) # frequencies of specific items ...
#> [1] 1 2
type_freqs(flist, c("the", "man")) # ... in the requested order
#> [1] 2 1
type_freq(flist, "the")            # frequency of one item
#> [1] 2

# frequencies of specific items can also be printed using subsetting
flist[c("the", "man")] 
#> Frequency list (types in list: 2, tokens in list: 3)
#> <total number of tokens: 5>
#> rank orig_rank type abs_freq nrm_freq
#> ---- --------- ---- -------- --------
#>    1         1  the        2     4000
#>    2         3  man        1     2000
flist["the"]
#> Frequency list (types in list: 1, tokens in list: 2)
#> <total number of tokens: 5>
#> rank orig_rank type abs_freq nrm_freq
#> ---- --------- ---- -------- --------
#>    1         1  the        2     4000