Skip to contents

This method returns the number of types in an object.

Usage

n_types(x, ...)

# S3 method for assoc_scores
n_types(x, ...)

# S3 method for freqlist
n_types(x, ...)

# S3 method for tokens
n_types(x, ...)

# S3 method for types
n_types(x, ...)

Arguments

x

An object of any of the classes for which the method is implemented.

...

Additional arguments.

Value

A number.

See also

Other getters and setters: n_tokens(), orig_ranks(), ranks(), tot_n_tokens(), type_names()

Examples

(tks <- tokenize("The old man and the sea."))
#> Token sequence of length 6
#> idx token
#> --- -----
#>   1   the
#>   2   old
#>   3   man
#>   4   and
#>   5   the
#>   6   sea

# for a types object ----------
(tps <- types(tks))
#> Type collection of length 5
#>   type
#>   ----
#> 1  the
#> 2  and
#> 3  man
#> 4  old
#> 5  sea
n_types(tps)
#> [1] 5

# for a freqlist object -------
(flist <- freqlist(tks))
#> Frequency list (types in list: 5, tokens in list: 6)
#> rank type abs_freq nrm_freq
#> ---- ---- -------- --------
#>    1  the        2 3333.333
#>    2  and        1 1666.667
#>    3  man        1 1666.667
#>    4  old        1 1666.667
#>    5  sea        1 1666.667
n_tokens(flist)
#> [1] 6
n_types(flist)
#> [1] 5

# for an assoc_scores object --
a <- c(10,    30,    15,    1)
b <- c(200, 1000,  5000,  300)
c <- c(100,   14,    16,    4)
d <- c(300, 5000, 10000, 6000)
types <- c("four", "fictitious", "toy", "examples")

(scores <- assoc_abcd(a, b, c, d, types = types))
#> Association scores (types in list: 4)
#>         type  a    PMI G_signed|   b   c     d dir  exp_a DP_rows
#> 1       four 10 -1.921  -45.432| 200 100   300  -1 37.869  -0.202
#> 2 fictitious 30  2.000   56.959|1000  14  5000   1  7.498   0.026
#> 3        toy 15  0.536    2.984|5000  16 10000   1 10.343   0.001
#> 4   examples  1  2.067    1.473| 300   4  6000   1  0.239   0.003
#> <number of extra columns to the right: 7>
#> 
n_types(scores)
#> [1] 4