Programming with dplyr
Dr. Chester Ismay
Educator, Data Scientist, and R/Python Consultant
names(world_bank_data)
[1] "iso" "country" "continent"
[4] "region" "year" "infant_mortality_rate"
[7] "fertility_rate" "perc_electric_access" "perc_college_complete"
[10] "perc_cvd_crd_70" "unemployment_rate" "perc_rural_pop"
reordered_wb <- world_bank_data %>% select(iso:year,matches("^perc"),everything())
names(reordered_wb)
[1] "iso" "country" "continent"
[4] "region" "year" "perc_electric_access"
[7] "perc_college_complete" "perc_cvd_crd_70" "perc_rural_pop"
[10] "infant_mortality_rate" "fertility_rate" "unemployment_rate"
world_bank_data %>% select(iso:year, matches("^perc"),infant_mortality_rate:last_col()) %>%names()
[1] "iso" "country" "continent"
[4] "region" "year" "perc_electric_access"
[7] "perc_college_complete" "perc_cvd_crd_70" "perc_rural_pop"
[10] "infant_mortality_rate" "fertility_rate" "unemployment_rate"
world_bank_data %>%relocate(matches("^perc"), .after = year) %>%names()
[1] "iso" "country" "continent"
[4] "region" "year" "perc_electric_access"
[7] "perc_college_complete" "perc_cvd_crd_70" "perc_rural_pop"
[10] "infant_mortality_rate" "fertility_rate" "unemployment_rate"
world_bank_data %>% relocate(matches("^perc"), .before = infant_mortality_rate) %>%names()
[1] "iso" "country" "continent"
[4] "region" "year" "perc_electric_access"
[7] "perc_college_complete" "perc_cvd_crd_70" "perc_rural_pop"
[10] "infant_mortality_rate" "fertility_rate" "unemployment_rate"
Programming with dplyr