Skip to content

Instantly share code, notes, and snippets.

@pboesu
Last active August 7, 2018 11:28
Show Gist options
  • Save pboesu/38e7fa95bd2f81a7ee684eb3c7ee10d6 to your computer and use it in GitHub Desktop.
Save pboesu/38e7fa95bd2f81a7ee684eb3c7ee10d6 to your computer and use it in GitHub Desktop.
Jenni's coding challenge
require(dplyr)
nuts1 <- readr::read_csv('NUTS1_kmsq.csv')
nuts1 %>% group_by(ONEKMREF) %>% summarise(biggest_area = max(kmsq_Area), biggest_area_index = which.max(kmsq_Area), biggest_area_name = Region_name[biggest_area_index] ) -> solution_df
#check for areas with multiple regions
nuts1 %>% group_by(ONEKMREF) %>% summarise(n_rows = n()) %>% arrange(desc(n_rows)) %>% head()
#check result
nuts1 %>% filter(ONEKMREF == 'NU2613') %>% select(ONEKMREF, Region_name, kmsq_Area)
solution_df %>% filter(ONEKMREF == 'NU2613')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment