Helper function to format a vector of strings using SI prefix notation

Format a vector of numeric values according to the International System of Units. http://en.wikipedia.org/wiki/SI_prefix

Based on code by Ben Tupper https://stat.ethz.ch/pipermail/r-help/2012-January/299804.html Args:

format_si(...)

Arguments

...

List of integer or numeric ...: Args passed to format()

Value

Formatted number.

Author

Someone

Examples

format_si()
#> function (x) #> { #> limits <- c(1e-24, 1e-21, 1e-18, 1e-15, 1e-12, 1e-09, 1e-06, #> 0.001, 1, 1000, 1e+06, 1e+09, 1e+12, 1e+15, 1e+18, 1e+21, #> 1e+24) #> prefix <- c("y", "z", "a", "f", "p", "n", "", "m", " ", "k", #> "M", "G", "T", "P", "E", "Z", "Y") #> i <- findInterval(abs(x), limits) #> i <- ifelse(i == 0, which(limits == 1), i) #> paste(format(round(x/limits[i], 1), trim = TRUE, scientific = FALSE, #> ...), prefix[i]) #> } #> <bytecode: 0x555b8529dec8> #> <environment: 0x555b8529c5d8>