as_numeric: Convert to numeric passing through character for safety

View source: R/as_numeric.R

as_numericR Documentation

Convert to numeric passing through character for safety

Description

Convert to numeric passing through character for safety

Usage

as_numeric(x, ..., require_conversion = NULL)

Arguments

x

vector

...

additional argument to as.character

require_conversion

If values are converted to NA, should nothing be done (NULL), a warning be printed (FALSE), or an error occur (TRUE)? (Inputs that are NA do not trigger the warning or error.)

See Also

Other Numerics: unique_non_numerics()

Examples

# factor with weird levels that we don't want to keep
ex <- factor(c(1, 2, 3, 4), levels = c(2, 3, 1, 4)) 
ex

# keeps information about the levels, oh no!
as.numeric(ex) 

# keeps the labelled values
as_numeric(ex)

as_numeric(c("1", "A"), require_conversion=FALSE)

metrumresearchgroup/PKPDmisc documentation built on Oct. 21, 2022, 9:41 a.m.