Skip to contents

This function converts length and area values from one unit to another (e.g., meters to miles, or square yards to acres). Alternatively, it provides the conversion factor for changing one unit to another.

Usage

convertUnits(from = NULL, to = NULL, x = NULL)

Arguments

from, to

Character: Names of the units to convert from/to. Partial matching is used, and case is ignored. Valid values are listed below. The '*2' values represent areas (e.g., 'm2' is "meters-squared").

  • 'm' or 'meters'

  • 'm2' or 'meters2'

  • 'km' or 'kilometers'

  • 'km2' or 'kilometers2'

  • 'mi' or 'miles'

  • 'mi2' or 'miles2'

  • 'ft' or 'feet'

  • 'ft2' or 'feet2'

  • 'yd' or 'yards'

  • 'yd2' or 'yards2'

  • 'ac' or 'acres'

  • 'ha' or 'hectares'

  • 'nmi' or 'nautical miles'

  • 'nmi2' or 'nautical miles2'

x

Numeric or NULL (default). The value(s) to convert in the unit specified by from. If left as NULL, the conversion factor is reported instead.

Examples


# conversion
convertUnits(from = 'm', to = 'km', 250)
#> [1] 0.25
convertUnits(from = 'm', to = 'mi', 250)
#> [1] 0.1553428
convertUnits(from = 'm2', to = 'km2', 250)
#> [1] 0.00025

# conversion factors 
convertUnits(from = 'm', to = 'km')
#> [1] 0.001
convertUnits(from = 'm')
#>      from             to      factor
#> 45 meters           feet 3.280840000
#> 46 meters     kilometers 0.001000000
#> 47 meters         meters 1.000000000
#> 48 meters          miles 0.000621371
#> 49 meters nautical miles 0.000539957
#> 50 meters          yards 1.093613298
convertUnits(to = 'm')
#>              from     to    factor
#> 11           feet meters    0.3048
#> 33     kilometers meters    0.0010
#> 47         meters meters    1.0000
#> 61          miles meters 1609.3400
#> 75 nautical miles meters 1852.0000
#> 89          yards meters    0.9144