Title: | Format a number to a string with SI prefix |
---|---|
Description: | Format a number (or a list of numbers) to a string (or a list of strings) with SI prefix. Use SI prefixes as constants like (4 * milli)^2 |
Authors: | Jonas Stein, Ben Tupper |
Maintainer: | Jonas Stein <[email protected]> |
License: | GPL-3 |
Version: | 1.4 |
Built: | 2025-02-16 03:44:33 UTC |
Source: | https://github.com/cran/sitools |
tools to handle prefixes as defined in Systeme International d Unites.
Package: | sitools |
Type: | Package |
Version: | 1.2 |
Date: | 2012-01-23 |
License: | GPL-3 |
LazyLoad: | yes |
Jonas Stein, thanks to Ben Tupper, Roland Fu(sz) Maintainer: Jonas Stein <[email protected]>
f2si(0.001)
f2si(0.001)
Convert a single or a list of float or integer to a string using SI prefixes.
f2si(number, unit="")
f2si(number, unit="")
number |
number to convert |
unit |
string to attach behind the SI prefix |
Main application of this function is to get nice strings to place at axis ticks. In this case some prefixes like deka are not used. This function will only generate 10^(3*n) prefixes for positive numbers at the moment. This may change soon.
comp1 |
string using SI prefixes |
package is still in alpha stage
Jonas Stein [email protected] https://github.com/jonasstein/sitools
http://www.bipm.org/en/si/si_brochure/chapter3/prefixes.html
library(sitools) # convert single number f2si(10000) # convert single number with unit f2si(0.023, unit="V") # convert list of numbers numbers <- c(1e5, 3.5e19, 0.004) f2si(numbers) # how to create fancy axis labels # generate some data xdata <- 10^(0:10) ydata <- sin(xdata)^2 # lets assume the ticks should be at 1,2,4 ..10,20,40... tickvalues <- 10^(0:10) # plot the data and generate axis plot(x=xdata, y=ydata, log="x", xlim=c(1,1e10), xaxt="n",xlab="Frequency (Hz)") axis(1, at=tickvalues, labels=f2si(tickvalues))
library(sitools) # convert single number f2si(10000) # convert single number with unit f2si(0.023, unit="V") # convert list of numbers numbers <- c(1e5, 3.5e19, 0.004) f2si(numbers) # how to create fancy axis labels # generate some data xdata <- 10^(0:10) ydata <- sin(xdata)^2 # lets assume the ticks should be at 1,2,4 ..10,20,40... tickvalues <- 10^(0:10) # plot the data and generate axis plot(x=xdata, y=ydata, log="x", xlim=c(1,1e10), xaxt="n",xlab="Frequency (Hz)") axis(1, at=tickvalues, labels=f2si(tickvalues))
SI prefixes are defined as constant factors like kilo <- 1000
SI prefixes are defined as constant factors like kilo <- 1000 The use of constants for SI prefixes will make your code readable. It reduces the risk of mistakes and supports the usage of SI units. The BIPM provides a list of prefixes. All of them are available as constants in sitools.
Jonas Stein [email protected] https://github.com/jonasstein/sitools
http://www.bipm.org/en/si/si_brochure/chapter3/prefixes.html
library(sitools) # dice have a volume of (in metres) a <- 1 * centi volumedice <- a^3 volumedice # how many dice fit in a box with # 10 cm height # 20 cm length # 30 cm width volumebox <- 10*centi * 20*centi * 30*centi volumebox / volumedice
library(sitools) # dice have a volume of (in metres) a <- 1 * centi volumedice <- a^3 volumedice # how many dice fit in a box with # 10 cm height # 20 cm length # 30 cm width volumebox <- 10*centi * 20*centi * 30*centi volumebox / volumedice