Convert values to different units
convert_values(x, from, to, messages)
a numeric vector of values to convert
units to convert from
units to convert to
should messages be printed when
a numeric vector of the converted values
Currently supported units for from
and to
are:
c("ng/L", "ug/L", "mg/L", "g/L", "kg/L", "pH", "degC", "C", "CFU/dL", "MPN/dL", "CFU/100mL", "MPN/100mL", "CFU/g", "MPN/g", "CFU/mL", "MPN/mL", "Col.unit", "Rel", "NTU", "m", "uS/cm")
convert_values(1, "ug/L", "mg/L", messages = FALSE)
#> [1] 0.001
df <- data.frame(
value = c(1.256, 5400000, 12300, .00098),
units = c("mg/L", "ng/L", "ug/L", "g/L"),
stringsAsFactors = FALSE
)
df
#> value units
#> 1 1.256e+00 mg/L
#> 2 5.400e+06 ng/L
#> 3 1.230e+04 ug/L
#> 4 9.800e-04 g/L
df$units_mg_L <- convert_values(df$value, from = df$units, to = "mg/L", messages = FALSE)
df
#> value units units_mg_L
#> 1 1.256e+00 mg/L 1.256
#> 2 5.400e+06 ng/L 5.400
#> 3 1.230e+04 ug/L 12.300
#> 4 9.800e-04 g/L 0.980