convert_unit: Modify a vector or dataframe-columns by converting units.

Description Usage Arguments Value See Also Examples

Description

convert_unit() of a vector or convert_unit_at() specific columns of a dataframe.

Usage

1
2
3
convert_unit(x, from, to)

convert_unit_at(x, .at, from, to)

Arguments

x

A vector or dataframe.

from

the unit in which the measurement was made.

to

the unit to which the measurement is to be converted.

.at

A character vector of names, positive numeric vector of positions to include, or a negative numeric vector of positions to exlude. Only those elements corresponding to .at will be modified. If the tidyselect package is installed, you can use vars() and the tidyselect helpers to select elements.

Value

An object with the same structure as x (vector or dataframe).

See Also

measurements::conv_unit(), purrr::map_at().

Other general functions to perform common transforms: standardize_at

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# For all units see ?measurements::conv_unit()
convert_unit(10, "mm2", "hectare")
convert_unit(1:3, from = "m", to = "mm")
convert_unit(1:3, "mph", "kph")

dfm <- data.frame(dbh = c(10, 100), name = c(10, 100))
convert_unit_at(dfm, .at = "dbh", from = "mm2", to = "hectare")
# All columns
convert_unit_at(dfm, .at = c("dbh", "name"), from = "mm2", to = "hectare")
# Same
convert_unit_at(dfm, .at = names(dfm), from = "mm2", to = "hectare")

forestgeo/fgeo.misc documentation built on June 23, 2019, 6:26 p.m.