Skip to contents

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.

Usage

dta_bmi(
  dat,
  .weight,
  .height,
  weight_units = c("kg", "lbs"),
  height_units = c("m", "in"),
  name = "bmi",
  digits = NULL
)

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.

Value

A tibble with the calculated body mass index (BMI).

Examples

data("data_bmi")
dta_gtable(data_bmi)
id age height weight
STM/4921 50 1.64 59
STM/4396 34 1.98 57
STM/7908 50 1.95 84
STM/7243 39 1.52 63
STM/4801 52 1.69 65
STM/5134 50 1.71 73
STM/7138 35 1.73 46
STM/6802 72 1.98 70
STM/4420 42 1.62 103
STM/6351 40 1.89 96
STM/4933 38 1.91 67
STM/4303 37 1.56 75
STM/7465 45 1.62 44
STM/4587 67 1.38 51
STM/5320 44 1.37 63
# Calculate BMI from the columns `weight` and `height` df <- dta_bmi( dat = data_bmi, .weight = weight, .height = height ) dta_gtable(df)
id age height weight bmi
STM/4921 50 1.64 59 21.93635
STM/4396 34 1.98 57 14.53933
STM/7908 50 1.95 84 22.09073
STM/7243 39 1.52 63 27.26801
STM/4801 52 1.69 65 22.75831
STM/5134 50 1.71 73 24.96495
STM/7138 35 1.73 46 15.36971
STM/6802 72 1.98 70 17.85532
STM/4420 42 1.62 103 39.24707
STM/6351 40 1.89 96 26.87495
STM/4933 38 1.91 67 18.36572
STM/4303 37 1.56 75 30.81854
STM/7465 45 1.62 44 16.76574
STM/4587 67 1.38 51 26.78009
STM/5320 44 1.37 63 33.56599
# 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)
id age height weight body_mass_index
STM/4921 50 1.64 59 21.94
STM/4396 34 1.98 57 14.54
STM/7908 50 1.95 84 22.09
STM/7243 39 1.52 63 27.27
STM/4801 52 1.69 65 22.76
STM/5134 50 1.71 73 24.96
STM/7138 35 1.73 46 15.37
STM/6802 72 1.98 70 17.86
STM/4420 42 1.62 103 39.25
STM/6351 40 1.89 96 26.87
STM/4933 38 1.91 67 18.37
STM/4303 37 1.56 75 30.82
STM/7465 45 1.62 44 16.77
STM/4587 67 1.38 51 26.78
STM/5320 44 1.37 63 33.57