3.14 Exercise - filter(), summarise(), spread()

Still working with gbd_full:

  • Filter for 1990.
  • Calculate the total number of deaths in the different income groups (High, Upper-Middle, Lower-Middle, Low). Hint: use group_by(income) and summarise(new_column_name = sum(variable)).
  • Calculate the total number of deaths within each income group for males and females. Hint: this is as easy as adding , sex to group_by(income).

  • spread() the income column.

Solution

## # A tibble: 2 x 5
##   sex     High   Low `Lower-Middle` `Upper-Middle`
##   <chr>  <dbl> <dbl>          <dbl>          <dbl>
## 1 Female 4.140  2.22           8.47          6.68 
## 2 Male   4.46   2.57           9.83          7.950