Skip to content

Instantly share code, notes, and snippets.

@giacecco
Created July 26, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giacecco/44eff5f4c9bc1727b40e to your computer and use it in GitHub Desktop.
Save giacecco/44eff5f4c9bc1727b40e to your computer and use it in GitHub Desktop.
# load ONS' pcd11_oa11_lsoa11_msoa11_lad11_ew_lu dataset and get the list of output areas for the
# relevant postcodes
onspcenum_oas <- unique((read.csv(pipe("unzip -qc \"/Users/giacecco/Data archive/ons/pcd11_oa11_lsoa11_msoa11_lad11_ew_lu/150725/Postcodes_(Enumeration)_(2011)_to_output_areas_(2011)_to_lower_layer_SOA_(2011)_to_middle_layer_SOA_(2011)_to_local_authority_districts_(2011)_E+W_lookup.zip\" *.csv"), na.strings = c(""), stringsAsFactors = F) %>% filter(PCD7 %in% union(lrpp_postcodes$pcd, oson_postcodes$pcd)))$OA11CD)
# load ONS' NSAL for the relevant output areas
onsnsal_property_no <- collect(tbl(src_postgres("olaf"), sql(paste0("SELECT COUNT(uprn) AS no_of_properties FROM ons_nsal WHERE oa11 IN (", paste0("'", onspcenum_oas, "'", collapse=", "), ")", collapse = ""))))$no_of_properties
> onsnsal_property_no
[1] 237702
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment