library(knitr) opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE, cache=FALSE) devtools::load_all(here::here())
The first question we want to investigate is at what age people marry. This data is available in the year_of_birth tab of the marriage files.
We'd like to have a single dataframe indicating for each age how many people marry. However, when loading the data isn't coded in the way we want.
select_worksheet(worksheet = "year_of_birth", year = "2013", type = "divorce")[1:20, ]
There are several issues:
We create a function to solve each issue, apply these to each dataframe and then bind all dataframes for each year together. Small note: additional data on gender is provided from 2015 on. Making a modification to incorporate this hasn't been done yet so for the moment the focus is on the data 2013-2014.
types <- c("divorce","marriage") years <- paste0("201", 3:4) rep_years <- rep(years, times = length(types)) rep_types <- rep(types, each = length(years)) worksheets <- map2(.x = rep_years, .y = rep_types, .f = ~select_worksheet(worksheet = "year_of_birth", year = .x, type = .y) ) tidy_args <- list(worksheet = worksheets, year = rep_years, type = rep_types) tidy_dfs <- pmap(tidy_args, function(worksheet, year, type) tidy_year_of_birth(worksheet, year, type) ) year_of_birth <- bind_together(tidy_dfs) save(year_of_birth, file = paste(data_path, "year_of_birth.RData", sep = "/") ) # data_path is object in tidy-year_of_birth.R
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.