Transform a vector into numeric if meaningful, even with bad decimal, space or %

as_mon_numeric(vec)

Arguments

vec

a vector

Value

a numeric vector

Details

Note that text and factors are not transformed as numeric (except FALSE, TRUE, F, T), contrary to R default behavior with `as.numeric(factor())`

Examples

as_mon_numeric(c("1", "0", "1"))
#> [1] 1 0 1
as_mon_numeric(c("1.3", "1,5", "1;6", "16%", "17 87 "))
#> [1]    1.3    1.5    1.6   16.0 1787.0
as_mon_numeric(c(TRUE, "A", "F"))
#> Warning: NAs introduced by coercion
#> [1]  1 NA  0
as_mon_numeric(c(TRUE, TRUE, FALSE))
#> [1] 1 1 0
as_mon_numeric(factor(c("toto", "tata", "toto")))
#> Warning: NAs introduced by coercion
#> [1] NA NA NA