Learn R Programming

DescTools (version 0.99.56)

ConvUnit: Unit Conversion and Metrix Prefixes

Description

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.

Usage

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.

Author

Andri Signorell <andri@signorell.net>

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.

Examples

Run this code
ConvUnit(c(1.2, 5.4, 6.7), "in", "m")

# from kilometers to pico meters
ConvUnit(1, from="km", to="pm")

# from miles to kilometers
ConvUnit(1, from="mi", to="km")
# nautical miles
ConvUnit(1, from="nmi", to="km")
# from kilo Kelvin to Fahrenheit
ConvUnit(10, from="kK", to="F")
# from metric to more quirky units
ConvUnit(c(10, 1), from="hl", to="gal")
ConvUnit(500, from="ml", to="fl oz")

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

Run the code above in your browser using DataLab