robust_values {popEpi} | R Documentation |
Convert values to numeric robustly
Description
Brute force solution for ensuring a variable is numeric by coercing a variable of any type first to factor and then to numeric
Usage
robust_values(num.values, force = FALSE, messages = TRUE)
Arguments
num.values |
values to convert to numeric |
force |
logical; if |
messages |
logical; if |
Value
A numeric vector.
Note
Returns NULL
if given num.values
is NULL
.
Author(s)
Joonas Miettinen
Examples
## this works
values <- c("1", "3", "5")
values <- robust_values(values)
## this works
values <- c("1", "3", "5", NA)
values <- robust_values(values)
## this returns originals and throws warnings
values <- c("1", "3", "5", "a")
suppressWarnings(
values <- robust_values(values)
)
## this forces "a" to NA and works otherwise; throws warning about NAs
values <- c("1", "3", "5", "a")
suppressWarnings(
values <- robust_values(values, force=TRUE)
)
[Package popEpi version 0.4.12 Index]