PostcodesioR 0.1.1 is on CRAN
This article is originally published at https://walczak.org
This package is based exclusively on open data provided by Ordnance Survey and Office for National Statistics and turned into an API by postcodes.io.
PostcodesioR can be used by data scientists or social scientists working with geocoded UK data. A common task when working with such data is aggregating data at different administrative levels, e.g. turning postcode-level data into counties or regions. This package can help in achieving this goal and in many other cases involving geospatial data.
The package can be installed from CRAN with
or from GitHub
Once the package is installed, load it with
The workhorse of the package is the
postcode_lookup() function which takes a postcode and returns a data frame with the following fields:
postcodePostcode. All current (‘live’) postcodes within the United Kingdom, the Channel Islands and the Isle of Man, received monthly from Royal Mail. 2, 3 or 4-character outward code, single space and 3-character inward code.
qualityPositional Quality. Shows the status of the assigned grid reference.
eastingsEastings. The Ordnance Survey postcode grid reference Easting to 1 metre resolution; blank for postcodes in the Channel Islands and the Isle of Man. Grid references for postcodes in Northern Ireland relate to the Irish Grid system.
northingsNorthings. The Ordnance Survey postcode grid reference Easting to 1 metre resolution; blank for postcodes in the Channel Islands and the Isle of Man. Grid references for postcodes in Northern Ireland relate to the Irish Grid system.
countryCountry. The country (i.e. one of the four constituent countries of the United Kingdom or the Channel Islands or the Isle of Man) to which each postcode is assigned.
nhs_haStrategic Health Authority. The health area code for the postcode.
longitudeLongitude. The WGS84 longitude given the Postcode’s national grid reference.
latitudeLatitude. The WGS84 latitude given the Postcode’s national grid reference.
european_electoral_regionEuropean Electoral Region (EER). The European Electoral Region code for each postcode.
primary_care_trustPrimary Care Trust (PCT). The code for the Primary Care areas in England, LHBs in Wales, CHPs in Scotland, LCG in Northern Ireland and PHD in the Isle of Man; there are no equivalent areas in the Channel Islands. Care Trust/ Care Trust Plus (CT) / local health board (LHB) / community health partnership (CHP) / local commissioning group (LCG) / primary healthcare directorate (PHD).
regionRegion (formerly GOR). The Region code for each postcode. The nine GORs were abolished on 1 April 2011 and are now known as ‘Regions’. They were the primary statistical subdivisions of England and also the areas in which the Government Offices for the Regions fulfilled their role. Each GOR covered a number of local authorities.
lsoa2011 Census lower layer super output area (LSOA). The 2011 Census lower layer SOA code for England and Wales, SOA code for Northern Ireland and data zone code for Scotland.
msoa2011 Census middle layer super output area (MSOA). The 2011 Census middle layer SOA (MSOA) code for England and Wales and intermediate zone for Scotland.
incodeIncode. 3-character inward code that is following the space in the full postcode.
outcodeOutcode. 2, 3 or 4-character outward code. The part of postcode before the space.
parliamentary_constituencyWestminster Parliamentary Constituency. The Westminster Parliamentary Constituency code for each postcode.
admin_districtDistrict. The current district/unitary authority to which the postcode has been assigned.
parishParish (England)/ community (Wales). The smallest type of administrative area in England is the parish (also known as ‘civil parish’); the equivalent units in Wales are communities.
admin_countyCounty. The current county to which the postcode has been assigned.
admin_wardWard. The current administrative/electoral area to which the postcode has been assigned.
ccgClinical Commissioning Group. Clinical commissioning groups (CCGs) are NHS organisations set up by the Health and Social Care Act 2012 to organise the delivery of NHS services in England.
nutsNomenclature of Units for Territorial Statistics (NUTS) / Local Administrative Units (LAU) areas. The LAU2 code for each postcode. NUTS is a hierarchical classification of spatial units that provides a breakdown of the European Union’s territory for producing regional statistics which are comparable across the Union. The NUTS area classification in the United Kingdom comprises current national administrative and electoral areas, except in Scotland where some NUTS areas comprise whole and/or part Local Enterprise Regions. NUTS levels 1-3 are frozen for a minimum of three years and NUTS levels 4 and 5 are now Local Administrative Units (LAU) levels 1 and 2 respectively.
_codeReturns an ID or Code associated with the postcode. Typically these are a 9 character code known as an ONS Code or GSS Code. This is currently only available for districts, parishes, counties, CCGs, NUTS and wards.
One postcode can be geocoded in the following way
rss <- postcode_lookup("EC1Y8LX")
More than one postcode can be geocoded using purrr
postcodes <- c("EC1Y8LX", "SW1X 7XL")
postcodes_df <- purrr::map_df(postcodes, postcode_lookup)
The remaining functions are demonstrated in the vignette.
Documentation and participation
To read the full documentation of the PostcodesioR package, you can follow this link to the pkgdown site.
If you want to help with developing the package, report bugs or propose pull requests, you will find the GitHub page here.
Please visit source website for post related comments.