Cast values to desired data type.

deterge_to_double(x, bound_lower, bound_upper)
deterge_to_integer(x, bound_lower, bound_upper)
deterge_to_ascii(x, substitution_character)

Arguments

x

The input vector that needs to be cast/converted. Required.

bound_lower

Elements below this inclusive threshold will be set to NA.

bound_upper

Elements above this inclusive threshold will be set to NA.

substitution_character

If the character does not have an equivalent in ASCII, replace it with this character. Defaults to a question mark (i.e., '?').

Value

An array of values.

Details

The functions deterge_to_double() and deterge_to_integer() accept character representations of a number, and return a numeric or integer vector. Elements outside bound_lower and bound_upper are converted to NA_real_/NA_integer_.

The function deterge_to_ascii() accepts a character vector and returns a character vector. The encoding is changed to ASCII. Individual elements are allowed to be NA_character_.

See also

The real work in deterge_to_ascii() is performed by base::iconv(). base::iconv(x=x, from="latin1", to="ASCII//TRANSLIT", sub=substitution_character)

Author

Will Beasley

Examples

library(OuhscMunge)
deterge_to_double(c(NA, 1:10), 4, 8)
#>  [1] NA NA NA NA  4  5  6  7  8 NA NA
deterge_to_integer(c(NA, 1:10), 4L, 8L)
#>  [1] NA NA NA NA  4  5  6  7  8 NA NA

x <- c("Ekstr\xf8m", "J\xf6reskog", "bi\xdfchen Z\xfcrcher")
deterge_to_ascii(x)
#> [1] "Ekstrom"            "J\"oreskog"         "bisschen Z\"urcher"