View source: R/utility_functions.R
robust_values | R Documentation |
Brute force solution for ensuring a variable is numeric by coercing a variable of any type first to factor and then to numeric
robust_values(num.values, force = FALSE, messages = TRUE)
num.values |
values to convert to numeric |
force |
logical; if |
messages |
logical; if |
A numeric vector.
Returns NULL
if given num.values
is NULL
.
Joonas Miettinen
## 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)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.