# NOT RUN {
# Calculation and interpretation of a person's body-mass index (mass in kilograms)
bmi <- function(mass, size) {
ind <- mass / size^2
switchCase(
ind,
alt(
..expr <= 15,
{ cat("Your body mass index is ", ind, " which is very severely underweight.\n") },
"very severely underweight"
),
alt(
..expr > 15 & ..expr <= 16,
{ cat("Your body mass index is ", ind, " which is severely underweight.\n") },
"severely underweight"
),
alt(
..expr > 16 & ..expr <= 18.5,
{ cat("Your body mass index is ", ind, " which is underweight.\n") },
"underweight"
),
alt(
..expr > 18.5 & ..expr <= 25,
{ cat("Your body mass index is ", ind, " which is normal.\n") },
"normal"
),
alt(
..expr > 25 & ..expr <= 30,
{ cat("Your body mass index is ", ind, " which is overweight.\n") },
"overweight"
),
alt(
..expr > 30 & ..expr <= 35,
{ cat("Your body mass index is ", ind, " which is moderately obese.\n") },
"moderately obese"
),
alt(
..expr > 35 & ..expr <= 40,
{ cat("Your body mass index is ", ind, " which is severely obese.\n") },
"severly obese"
),
alt(
..expr > 40,
{ cat("Your body mass index is ", ind, " which is Very severely obese.\n") },
"very severly obese"
)
)
}
bmi.person1 <- bmi(82.5, 1.79)
cat("Person1 turned out to be ", bmi.person1)
# }
Run the code above in your browser using DataLab