Skip to contents

Arithmetic and most mathematical operations are supported on the numeric component of shrthnd_num() vectors via the {vctrs} package without having to wrap the vector in as.numeric().

Details

You can use all the standard arithmetic infix operators (+, -, /, *, ^, %%, %/%, !). See vctrs::vec_arith() for further details.

Through vctrs::vec_math() the following generic mathematical operations are supported:

For other operations you will need to wrap the shrthnd_num vector in as.numeric().

For all operations remember that you will likely need to set na.rm = TRUE or whatever other method a function has for ignoring missing values.

Examples

x <- c("12", "34.567", "[c]", "NA", "56.78[e]", "78.9", "90.123[e]")
sh_x <- shrthnd_num(x, c("[c]", "[e]"))

sh_x * 2
#> [1]  24.000  69.134      NA      NA 113.560 157.800 180.246

2 + sh_x
#> [1] 14.000 36.567     NA     NA 58.780 80.900 92.123

mean(sh_x, na.rm = TRUE)
#> [1] 54.474