dta_bmi() computes the Body Mass Index (BMI) given weight and height
columns in a data frame or tibble. It allows customization for weight and
height units.
Arguments
- dat
A data frame or tibble containing the weight and height columns.
- .weight
Name of the column representing weight in the data.
- .height
Name of the column representing height in the data.
- weight_units
Character string specifying the units of weight. Options are
"kg"for kilograms or"lbs"for pounds. Default is"kg".- height_units
Character string specifying the units of height. Options are
"m"for meters or"in"for inches. Default is"m".- name
Character string specifying the name of the new BMI column. Default is
bmi.- digits
Integer specifying the number of decimal places for rounding the BMI value. Default is
NULL.
Examples
data("data_bmi")
dta_gtable(data_bmi)
# Calculate BMI from the columns `weight` and `height`
df <- dta_bmi(
dat = data_bmi,
.weight = weight,
.height = height
)
dta_gtable(df)
# Calculate BMI from the columns `weight` and `height`
# to 2 decimal points and assign the values to the new
# variable named `body_mass_index`
df2 <- dta_bmi(
dat = data_bmi,
.weight = weight,
.height = height,
name = body_mass_index,
digits = 2
)
dta_gtable(df2)