convert_unit()
of a vector or convert_unit_at()
specific columns of a
dataframe.
convert_unit(x, from, to) convert_unit_at(x, .at, from, to)
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 |
An object with the same structure as x
(vector or dataframe).
measurements::conv_unit()
, purrr::map_at()
.
Other general functions to perform common transforms: standardize_at
# For all units see ?measurements::conv_unit() convert_unit(10, "mm2", "hectare")#> [1] 1e-09convert_unit(1:3, from = "m", to = "mm")#> [1] 1000 2000 3000convert_unit(1:3, "mph", "kph")#> [1] 1.609344 3.218688 4.828032dfm <- data.frame(dbh = c(10, 100), name = c(10, 100)) convert_unit_at(dfm, .at = "dbh", from = "mm2", to = "hectare")#> dbh name #> 1 1e-09 10 #> 2 1e-08 100#> dbh name #> 1 1e-09 1e-09 #> 2 1e-08 1e-08#> dbh name #> 1 1e-09 1e-09 #> 2 1e-08 1e-08