2.6 The combine function: c()

The combine function as it’s name implies is used to combine several values. It is especially useful when used with the %in% operator to filter for multiple values. Remember how the gbd_short cause column had three different causes in it:

## [1] "Communicable diseases"     "Injuries"                 
## [3] "Non-communicable diseases"

Say we wanted to filter for communicable and non-communicable diseases.7 We could use the OR operator | like this:

## # A tibble: 2 x 3
##    year cause                     deaths_millions
##   <dbl> <chr>                               <dbl>
## 1  1990 Communicable diseases                15.4
## 2  1990 Non-communicable diseases            26.7

But that means we have to type in cause twice (and more if we had other values we wanted to include). This is where the %in% operator together with the c() function come in handy:

## # A tibble: 2 x 3
##    year cause                     deaths_millions
##   <dbl> <chr>                               <dbl>
## 1  1990 Communicable diseases                15.4
## 2  1990 Non-communicable diseases            26.7

  1. In this example, it would just be easier to used the “not equal” operator, filter(cause != “Injuries”), but imagine your column had more than just three different values in it.