Last active
April 1, 2021 09:43
-
-
Save Lextuga007/d6564ce0de320237ac1e11ebf00b87eb to your computer and use it in GitHub Desktop.
Function
This file contains hidden or 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
| tidy_imd <- function(data, tidy_imd_vars = NULL){ | |
| # First rename all variables | |
| data <- data %>% | |
| dplyr::select(lsoa_code_2011 = LSOAcode2011, | |
| lsoa_name_2011 = LSOAname2011, | |
| everything()) %>% | |
| janitor::clean_names() %>% | |
| dplyr::select(lsoa_code_2011, | |
| lsoa_name_2011, | |
| la_district_code2019, | |
| la_district_name2019, | |
| imd_decile, | |
| imd_quintile, | |
| notts_wide_decile, | |
| notts_wide_quintile) | |
| if (is.null(tidy_imd_vars)){ | |
| return(data) | |
| } | |
| else if (tidy_imd_vars == "nottingham"){ | |
| return(data %>% | |
| dplyr::filter(!is.na(notts_wide_decile)) | |
| ) | |
| } | |
| else if (tidy_imd_vars == "england") { | |
| return(data %>% | |
| dplyr::select(lsoa_code_2011, | |
| lsoa_name_2011, | |
| la_district_code2019, | |
| la_district_name2019, | |
| imd_decile, | |
| imd_quintile)) | |
| } | |
| else if (tidy_imd_vars == "derbyshire") { | |
| return(data %>% | |
| dplyr::select(lsoa_code_2011, | |
| lsoa_name_2011) | |
| ) | |
| } | |
| } | |
| test_default <- tidy_imd(data = df_imd) | |
| test_nottingham <- tidy_imd(data = df_imd, tidy_imd_vars = "nottingham") | |
| test_england <- tidy_imd(data = df_imd, tidy_imd_vars = "england") | |
| test_derbyshire <- tidy_imd(data = df_imd, tidy_imd_vars = "derbyshire") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment