Intermezzo: missing values (7)

Notice the effect of names_expand and values_fill in pivot_wider()!

percentages |>
  pivot_wider(
    names_from = c(year, type),
    values_from = percentage,
    names_expand = TRUE,
    values_fill = 0
  )
## # A tibble: 1 × 6
##   `2018_A` `2018_B` `2019_A` `2019_B` `2020_A` `2020_B`
##      <dbl>    <dbl>    <dbl>    <dbl>    <dbl>    <dbl>
## 1      100        0        0      100       40       60