Skip to contents

Convert MUAC values to either centimeters or millimeters as required. Before to covert, the function checks if the supplied MUAC values are in the opposite unit of the intended conversion. If not, execution stops and an error message is returned.

Usage

recode_muac(x, .to = c("cm", "mm"))

Arguments

x

A vector of raw MUAC values. The class can either be double or numeric or integer. If different than expected, the function will stop execution and return an error message indicating the type of mismatch.

.to

A choice between cm (centimeters) and mm (millimeters) for the measuring unit to convert MUAC values to. Before to execute the conversion, the function checks if values are in the opposite unit; in case not, the execution stops and an error message is returned. Strive to address the error and try again.

Value

A numeric vector of the same length as x, with values converted to the chosen measuring unit.

Examples

## Recode from millimeters to centimeters ----
muac_cm <- recode_muac(
  x = anthro.01$muac,
  .to = "cm"
)
head(muac_cm)
#> [1] 14.6 12.7 14.2 14.9 14.3 13.2

## Using the `muac_cm` object to recode it back to "mm" ----
muac_mm <- recode_muac(
  x = muac_cm,
  .to = "mm"
)
tail(muac_mm)
#> [1] 149 149 168 168 152 140