R: Unit Conversion and Metrix Prefixes

ConvUnit {DescTools} | R Documentation

## 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

    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 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 | g | metric
Pound mass (avoirdupois) | lb
Ounce mass (avoirdupois) | oz
Metric ton | ton (or tn)
Distance |
Meter | m | metric
Statute mile | mi
Nautical mile | nmi
Inch | in
Foot | ft
Yard | yd
Angstrom | AA | (accepted) metric
Astronomical unit | au |
Time |
Year | a
Day | d
Hour | h
Minute | min
Second | s
Pressure |
Pascal | Pa
Atmosphere | atm
mm of Mercury | mmHg
bar | bar
Pound-force per quare inch | psi
Energy |
Joule | J | metric
IT calorie | cal | (accepted) metric
Electron volt | eV (or ev) |
Power |
Horsepower (mechanical) | hp
Horsepower (metric) | HP
Watt | W (or w) | metric
Temperature |
Degree Celsius | C
Degree Fahrenheit | F
Kelvin | K | metric
Liquid measure |
Fluid ounce | fl oz
Gallon | gal
Liter | l (or lt) | (accepted) metric

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

### Author(s)

Andri Signorell <andri@signorell.net>

### Examples

    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")

[Package DescTools version 0.99.28 Index]