Coalesce and Fill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## %######################################################%## | |
# # | |
#### Coalesce and Fill - Your Turn #### | |
# # | |
## %######################################################%## | |
# Load the fish landings data 'fish-landings.csv' | |
# Fill the 'Fish' and 'Lake' columns | |
# Reorder the numeric variables ('Comission reported total' first) | |
# create a new column, coalescing the three numeric variables | |
# load packages ----------------------------------------------------------- | |
library(readr) | |
library(dplyr) | |
library(tidyr) | |
# import data ------------------------------------------------------------- | |
fishlandings <- read_csv("data/fish-landings.csv") | |
# fill and coalesce | |
fishlandings %>% | |
fill(Fish, Lake) %>% | |
select(Fish, Lake, Month, `Commission reported total`, `Official total`, `Previous year total`) %>% | |
mutate(new_total = coalesce(`Commission reported total`, `Official total`, `Previous year total`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment