ln_convert_units.Rd
Convert values to the default units for the lab
ln_convert_units(values, units, lab)
a vector of lab values
the units of the lab values. See LAB_DETAILS$units
for a list of available units for each lab. If different values have different units then this should be a vector of the same length as values
.
the lab name. See LAB_DETAILS$short_name
for a list of available labs.
the values converted to the default units for the lab
# emulate a dataset with different units
hemoglobin_diff_units <- hemoglobin_data
# first 50 values will be in mg/ML
hemoglobin_diff_units$value[1:50] <- hemoglobin_diff_units$value[1:50] * 10
# last 50 values will be in mmol/L
hemoglobin_diff_units$value[51:100] <- hemoglobin_diff_units$value[51:100] / 1.61
converted <- ln_convert_units(
hemoglobin_diff_units$value[1:100],
c(rep("mg/mL", 50), rep("mmol/L", 50)),
"Hemoglobin"
)
#> ℹ Converting mg/mL to g/dL for lab Hemoglobin. Using the formula `0.1 * x`.
#> ℹ Converting mmol/L to g/dL for lab Hemoglobin. Using the formula `1.61 * x`.
head(converted)
#> [1] 9.39 14.03 14.44 15.80 12.06 12.89
head(hemoglobin_data$value)
#> [1] 9.39 14.03 14.44 15.80 12.06 12.89