as_numv: Convert a Suitable Character Vector to Numeric
Description
as_numv determines whether a character vector can be coerced to numeric
without generating new NA values and, if so, it makes that conversion
(similar to Stata's destring command).
Usage
as_numv(x, nan2na = TRUE, inf2na = TRUE)
Value
a vector, converted to numeric if feasible (else, the same character
vector that was supplied).
Arguments
x
a character vector.
nan2na
a logical argument. TRUE if the non-case-sensitive string "nan"
should be converted to NA.
inf2na
a logical argument. TRUE if the non-case-sensitive strings
"inf" or "-inf should be converted to NA.
Details
Core labelr functions coerce integers to characters and back, which
as_numv facilitates. Note that character values of "NA" (including "na",
"Na", and "nA") will be converted to NA and, by default, so will other
"irregular" values (in the sense of check_irregular).