Start by loading the NHANES
data like in the previous exercise.
library(NHANES)
data(NHANES)
1. Compute the average and standard deviation of the BPSysAve
variable
for females, but for each age group separately rather than a selected decade as in question 1.
Note that the age groups are defined by AgeDecade
. Hint: rather than
filtering by age and gender, filter by Gender
and then use group_by
.
Store the result in a data frame summary_female
with a mean
and a sd
column for the average and standard deviation respectively.
2. Repeat exercise 1 for males. Store the result in summary_male
3. We can actually combine both summaries for exercises 1 and 2 into
one line of code. This is because group_by
permits us to group by more
than one variable. Obtain one big summary table using
group_by(Gender, AgeDecade)
. Store the result in a data frame summary_complete
.