Learn R Programming

thinkr (version 0.16)

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

Description

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

Usage

as_mon_numeric(vec)

Value

a numeric vector

Arguments

vec

a 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

Run this code
as_mon_numeric(c("1", "0", "1"))
as_mon_numeric(c("1.3", "1,5", "1;6", "16%", "17 87 "))
as_mon_numeric(c(TRUE, "A", "F"))
as_mon_numeric(c(TRUE, TRUE, FALSE))
as_mon_numeric(factor(c("toto", "tata", "toto")))

Run the code above in your browser using DataLab