Skip to content

Instantly share code, notes, and snippets.

@giacecco
Last active September 9, 2016 14:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giacecco/599b043ce333249b0f8b to your computer and use it in GitHub Desktop.
Save giacecco/599b043ce333249b0f8b to your computer and use it in GitHub Desktop.
Open Addresses UK - Basic inference example
> library(dplyr)
> # I read the ZE postcode area data from the Open Addresses UK 'split'
> # CSV distro
> oa <- read.csv("~/Downloads/2014-12-10-openaddressesuk-addresses-only-split.csv/ZE.csv", stringsAsFactors=FALSE)
> # I drop the addresses whose Primary Addressable Objects (PAO) can't be
> # interpreted as numbers
> oa$pao <- as.integer(oa$pao)
Warning message:
NAs introduced by coercion
> oa <- oa[!is.na(oa$pao),]
> # I search for streets for which I have more than one address within the same
> # postcode and some gap between the smallest and largest house numbers.
> # Note that the actual algorithm we will use also checks if all house
> # numbers are even or odd, and infer the new house numbers accordingly.
> # The algorithm is described at https://github.com/theodi/shared/issues/504#issuecomment-72818881
> oa %>% group_by(postcode.name, street.name) %>% summarise (min_pao = min(pao), max_pao = max(pao), gap = max(pao) - min(pao) - 1) %>% filter(gap > 1)
Source: local data frame [17 x 5]
Groups: postcode.name
postcode.name street.name min_pao max_pao gap
1 ZE1 0AN COMMERCIAL STREET 8 14 5
2 ZE1 0BD COMMERCIAL STREET 58 99 40
3 ZE1 0DL COMMERCIAL STREET 68 82 13
4 ZE1 0EJ HILLHEAD 4 8 3
5 ZE1 0ER KING HARALD STREET 61 65 3
6 ZE1 0EX COMMERCIAL STREET 96 159 62
7 ZE1 0LX COMMERCIAL ROAD 6 22 15
8 ZE1 0NJ COMMERCIAL ROAD 47 66 18
9 ZE1 0QQ LESLIE ROAD 22 33 10
10 ZE1 0RE MURRAYSTON 26 42 15
11 ZE1 0SE FOGRALEA 5 30 24
12 ZE1 0SF UPPER BAILA 3 13 9
13 ZE1 0SR SANDY LOCH DRIVE 9 15 5
14 ZE1 0UG BLYDOIT PARK 5 27 21
15 ZE1 0UU HOGALEE 23 27 3
16 ZE2 9LF HULSIDALE 11 27 15
17 ZE2 9UA NORT GREENHOULLS 1 5 3
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment