unit_conv: performs common unit conversions

View source: R/unit_conv.R

unit_convR Documentation

performs common unit conversions

Description

This function is slowly getting better. Adding more unit conversions as I need them.

Usage

unit_conv(x, from, to, ...)

Arguments

x

input variable

from

original units

to

target units

...

additional arguments passed to specific conversions

Details

Function which performs common unit conversions

At the moment possible conversions are:

  • ‘g/m2’ to ‘kg/ha’

  • ‘kg/ha’ to ‘g/m2’

  • ‘lb’ to ‘kg’

  • ‘kg’ to ‘lb’

  • ‘maize bu’ to ‘kg’

  • ‘kg’ to ‘maize bu’

  • ‘soy bu’ to ‘kg’

  • ‘kg’ to ‘soy bu’

  • ‘maize bu/ac’ to ‘kg/ha’

  • ‘maize bu/ac’ to ‘g/m2’

  • ‘kg/ha’ to ‘maize bu/ac’

  • ‘g/m2’ to ‘maize bu/ac’

  • ‘soy bu/ac’ to ‘kg/ha’

  • ‘soy bu/ac’ to ‘g/m2’

  • ‘kg/ha’ to ‘soy bu/ac’

  • ‘g/m2’ to ‘soy bu/ac’

  • ‘mm’ to ‘inches’

  • ‘inches’ to ‘mm’

  • ‘lb/ac’ to ‘kg/ha’

  • ‘kg/ha’ to ‘lb/ac’

  • ‘lb/ac’ to ‘g/m2’

  • ‘g/m2’ to ‘lb/ac’

  • ‘decimal’ to ‘degrees’

  • ‘degrees’ to ‘decimal’

  • ‘Fahrenheit’ to ‘Celsius’

  • ‘Celsius’ to ‘Fahrenheit’

This is for metric and Imperial conversions Source: https://www.extension.iastate.edu/agdm/wholefarm/html/c6-80.html

Value

value of the input variable with new units

Examples


grain.yield.gm2 <- 600
grain.yield.kgha <- unit_conv(grain.yield.gm2, from = "g/m2", to = "kg/ha")
grain.yield.kgha
## Converting coordinates
require(sp)
unit_conv("42d 0' 0\" N", from = "degrees", to = "decimal")
unit_conv(42, from = "decimal", to = "degrees") ## EW by default
unit_conv(42, from = "decimal", to = "degrees", NS = TRUE)



apsimx documentation built on Sept. 11, 2024, 5:42 p.m.