## 3.12 Exercise - full_join(), percent()

For each cause, calculate its percentage to total deaths in each year.

Hint: Use full_join() on summary_data1 and summary_data2, and then use mutate() to add a new column called percentage.

Example result for a single year:

## Joining, by = "year"
## # A tibble: 3 x 5
##    year total_per_year cause                     total_per_cause percentage
##   <dbl>          <dbl> <chr>                               <dbl> <chr>
## 1  1990          46.32 Communicable diseases               15.36 33.161%
## 2  1990          46.32 Injuries                             4.25 9.175%
## 3  1990          46.32 Non-communicable diseases           26.71 57.664%

Solution

## Joining, by = "year"
## # A tibble: 21 x 5
##     year total_per_year cause                     total_per_cause percentage
##    <dbl>          <dbl> <chr>                               <dbl> <chr>
##  1  1990          46.32 Communicable diseases               15.36 33.161%
##  2  1990          46.32 Injuries                             4.25 9.175%
##  3  1990          46.32 Non-communicable diseases           26.71 57.664%
##  4  1995          48.91 Communicable diseases               15.11 30.893%
##  5  1995          48.91 Injuries                             4.53 9.262%
##  6  1995          48.91 Non-communicable diseases           29.27 59.845%
##  7  2000          50.38 Communicable diseases               14.81 29.397%
##  8  2000          50.38 Injuries                             4.56 9.051%
##  9  2000          50.38 Non-communicable diseases           31.01 61.552%
## 10  2005          51.25 Communicable diseases               13.89 27.102%
## # … with 11 more rows