ln_convert_units {labNorm}R Documentation

Convert values to the default units for the lab

Description

Convert values to the default units for the lab

Usage

ln_convert_units(values, units, lab)

Arguments

values

a vector of lab values

units

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.

lab

the lab name. See LAB_DETAILS$short_name for a list of available labs.

Value

the values converted to the default units for the lab

Examples


# 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"
)

head(converted)
head(hemoglobin_data$value)

[Package labNorm version 1.0.1 Index]