Skip to contents

This generic method turns its first argument x or at least part of the information in it into a numeric object. It is an alternative notation for base::as.numeric().

Usage

as_numeric(x, ...)

# S3 method for default
as_numeric(x, ...)

Arguments

x

An object to coerce.

...

Additional arguments.

Value

A numeric vector.

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

# extract frequency counts from a frequency list
as_numeric(flist)
#> [1] 3 2 1 1 1 1 1
as.numeric(flist)
#> [1] 3 2 1 1 1 1 1

# preferable alternative
type_freqs(flist)
#> [1] 3 2 1 1 1 1 1