Last active
January 12, 2021 22:36
-
-
Save luisDVA/d8c4c4839137eb19b3554e30d9292a83 to your computer and use it in GitHub Desktop.
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