Converts a numerical vector from one measurement system to another. Metric prefixes (as unit prefixes that precede a basic unit of measure to indicate a multiple or fraction of the unit) are respected.

CmToPts(x)
PtsToCm(x)

ConvUnit(x, from, to)

data(d.units)
data(d.prefix)

Arguments

x

the numeric to be converted.

from

a character defining the original unit.

to

a character defining the target unit.

Details

The two functions CmToPts() and PtsToCm() convert centimeters to points and vice versa. 1 cm corresponds to 28.35 points.

The units as defined by the International System of Units (SI) (m, g, s, A, K, mol, cd, Hz, rad, sr, N, Pa, J, W, C, V, F, Ohm, S, Wb, T, H, lm, lx, Bq, Gy, Sv, kat, l) can be used to convert between different prefixes. The following non SI-units can be chosen for conversion between different systems. NA will be returned if a conversion can't be found.
The function is using the conversion factors stored in the dataset d.units.

Weight and mass
Gram
gmetricPound mass (avoirdupois)
lbOunce mass (avoirdupois)oz
Metric tonton (or tn)
DistanceMeter
mmetricStatute mile
miNautical milenmi
InchinFoot
ftYardyd
AngstromAA(accepted) metric
Astronomical unitau
TimeYear
aDayd
HourhMinute
minSeconds
Pressure
PascalPaAtmosphere
atmmm of MercurymmHg
barbarPound-force per quare inch
psi
Energy
JouleJmetric
IT caloriecal(accepted) metric
Electron volteV (or ev)
PowerHorsepower (mechanical)
hpHorsepower (metric)HP
WattW (or w)metric
TemperatureDegree Celsius
CDegree FahrenheitF
KelvinKmetric
Liquid measure
Fluid ouncefl oz Gallon
galLiterl (or lt)

Additional details can be found in the d.units data.frame.

Author

Andri Signorell <andri@signorell.net>

Examples

ConvUnit(c(1.2, 5.4, 6.7), "in", "m")
#> [1] 0.03048 0.13716 0.17018

# from kilometers to pico meters
ConvUnit(1, from="km", to="pm")
#> [1] 1e+15

# from miles to kilometers
ConvUnit(1, from="mi", to="km")
#> [1] 1.609344
# nautical miles
ConvUnit(1, from="nmi", to="km")
#> [1] 1.852
# from kilo Kelvin to Fahrenheit
ConvUnit(10, from="kK", to="F")
#> [1] 18523.67
# from metric to more quirky units
ConvUnit(c(10, 1), from="hl", to="gal")
#> [1] 264.17205  26.41721
ConvUnit(500, from="ml", to="fl oz")
#> [1] 16.90674

# conversion between non-SI units
ConvUnit(1000, "yd", "mi")
#> [1] 0.5679333
# ... must be the same as
ConvUnit(ConvUnit(1000, "yd", "m"), "m", "mi")
#> [1] 0.5679333