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
ornumeric
orinteger
. 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) andmm
(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.
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