Take a character vector of percentages (e.g. "50%") and convert it to a numeric vector (e.g. 0.5).

sanitizePercent(object, ...)

# S4 method for atomic
sanitizePercent(object)

# S4 method for character
sanitizePercent(object)

Arguments

object

Object.

...

Additional arguments.

Value

Modified object. All percentage strings containing "%" (e.g. "50%") are converted to numeric proportions (e.g. 0.5).

Intended usage

This function is designed primarily to sanitize data imported from Microsoft Excel.

Examples

object <- c("100%", "10.0%", "1%", "0.1%", "0.01%") class(object)
#> [1] "character"
print(object)
#> [1] "100%" "10.0%" "1%" "0.1%" "0.01%"
x <- sanitizePercent(object) class(x)
#> [1] "numeric"
#> [1] 1e+00 1e-01 1e-02 1e-03 1e-04