Intermezzo: missing values (6)

Suppose we have this, and you want to make it wide and add zeros, not NAs:

percentages
## # A tibble: 4 × 3
##    year type  percentage
##   <dbl> <fct>      <dbl>
## 1  2018 A            100
## 2  2019 B            100
## 3  2020 A             40
## 4  2020 B             60
percentages |>
  pivot_wider(
    names_from = c(year, type),
    values_from = percentage
  )
## # A tibble: 1 × 4
##   `2018_A` `2019_B` `2020_A` `2020_B`
##      <dbl>    <dbl>    <dbl>    <dbl>
## 1      100      100       40       60

That’s not it…