Checks character or factor vector to determine whether it might be best to convert to
numeric.
Usage
inspect_type(x, xname = NULL, verbosity = 1L, thresh = 0.5, na.omit = TRUE)
Arguments
- x
Character or factor vector.
- xname
Character: Name of input vector x.
- verbosity
Integer: Verbosity level.
- thresh
Numeric: Threshold for determining whether to convert to numeric.
- na.omit
Logical: If TRUE, remove NA values before checking.
Details
All data can be represented as a character string. A numeric variable may be read as
a character variable if there are non-numeric characters in the data.
It is important to be able to automatically detect such variables and convert them,
which would mean introducing NA values.
Examples
x <- c("3", "5", "undefined", "21", "4", NA)
inspect_type(x)
#> 2026-02-22 18:59:28
#> Possible type error: x is a character, but perhaps should be numeric.
#> [inspect_type]
#> [1] "numeric"
z <- c("mango", "banana", "tangerine", NA)
inspect_type(z)
#> [1] "character"