From bf0092d104029c0007cf1bd6596b758d340ecaf2 Mon Sep 17 00:00:00 2001 From: Thomas Schwarzl Date: Mon, 1 Apr 2019 18:12:31 +0200 Subject: [PATCH] Add new file --- 01_baseR-dataHandling/extraChallenge.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 01_baseR-dataHandling/extraChallenge.R diff --git a/01_baseR-dataHandling/extraChallenge.R b/01_baseR-dataHandling/extraChallenge.R new file mode 100644 index 0000000..35c39b4 --- /dev/null +++ b/01_baseR-dataHandling/extraChallenge.R @@ -0,0 +1,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/ -- 2.24.1