Locate values outside base R's numeric grammar
which.nonnum.RdReturn the positions of present values that become missing when converted by
as.numeric(as.character(x)). Use this diagnostic to find labels, unit
suffixes, localized separators, or other text that base R cannot parse as a
number.
Value
An integer vector of ascending one-based positions. Returns
integer(0) when every non-missing value is accepted.
Details
Conversion warnings are suppressed. Original missing values, including a
numeric NaN, are excluded from the result. A present string such as
"NA" or "NaN" is reported because its conversion is missing while the
original element is not. Finite numbers and Inf are accepted by base R.
This helper does not apply toNumeric() first. Consequently, "1,25" is
reported even though toNumeric("1,25") returns 1.25. Values containing
units or currency symbols are also reported; neither units nor locale are
inferred.
See also
toNumeric() to normalize the package's supported separator
formats before numeric conversion.
Examples
x <- c("2.5", "1,25", "12 kg", NA, "Inf")
which.nonnum(x)
#> [1] 2 3
x[which.nonnum(x)]
#> [1] "1,25" "12 kg"