These methods retrieve or set the total number of tokens in
the corpus on which the frequency counts are based.
This total number of tokens may be higher than the sum of all frequency
counts in x
, for instance, if x
contains frequency counts
for a selection of items only, and not for all tokens in the corpus.
Usage
tot_n_tokens(x)
tot_n_tokens(x) <- value
# S3 method for freqlist
tot_n_tokens(x) <- value
# S3 method for freqlist
tot_n_tokens(x)
Arguments
- x
An object of any of the classes for which the method is implemented.
- value
Numerical value.
See also
Other getters and setters:
n_tokens()
,
n_types()
,
orig_ranks()
,
ranks()
,
type_names()
Examples
x <- freqlist("The man and the mouse.",
re_token_splitter = "(?xi) [:\\s.;,?!\"]+",
as_text = TRUE)
x
#> 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
tot_n_tokens(x)
#> [1] 5
y <- keep_types(x, c("man", "and"))
tot_n_tokens(y)
#> [1] 5
y
#> 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
tot_n_tokens(y) <- sum(y)
y
#> Frequency list (types in list: 2, tokens in list: 2)
#> rank orig_rank type abs_freq nrm_freq
#> ---- --------- ---- -------- --------
#> 2 3 man 1 5000
#> 1 2 and 1 5000
tot_n_tokens(y)
#> [1] 2