convert to numeric passing through character for safety

as_numeric(x, ...)

Arguments

x

vector

...

additional argument to as.character

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
#> [1] 1 2 3 4 #> Levels: 2 3 1 4
# keeps information about the levels, oh no! as.numeric(ex)
#> [1] 3 1 2 4
# keeps the labelled values as_numeric(ex)
#> [1] 1 2 3 4