extraChallenge.R 1005 Bytes
Newer Older
Thomas Schwarzl's avatar
Thomas Schwarzl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# load(url("http://www-huber.embl.de/users/klaus/BasicR/bodyfat.rda"))

# 1. make sure your bodyfat data frame has the "bmi" column
# 2. Is there a correlation between bmi & wrist.circum
# 3. create a new variable that indicates the category of each person's BMI.
# Here are the categories
# Underweight: BMI is 0 to 18.5.
# Normal weight: BMI is 18.5 to 24.9.
# Overweight: BMI is 25 to 29.9.
# Obese: BMI is 30 to 100
# Anything over 100 is very unusual
# To do this, check out the cut() function.
# If the built-in R help isn't clear, try googling: "R cut() examples"

# 4. what is the average wrist.circum for each bmi category?
# 5. do you have an NA in your data? can you figure out why?

bf <- bodyfat %>%
  mutate(bmi = (weight*0.454) / (height*.0254)^2) %>%
  mutate(bmiCat = cut(bmi,breaks = c(0,18.5,24.9,29.9,100),labels = c("under","normal","over","obese"))) %>%
  group_by(bmiCat) %>%
  summarise(meanWrist = mean(wrist.circum))


#https://www.r-bloggers.com/from-continuous-to-categorical/