Creating a postcode file in R from different public data sources

Following on from my previous post on creating a postcode file with the 2015 general election results I wanted to create a larger file with more variables. Some from the ONS lookups, others from different public datasets. The one I have added so far is the Office of Communications Broadband Coverage dataset from 2013.

The final dataset will contain for each postcode in the UK:

  • The 2015 general election result
  • The Westminster Election Constituency
  • The Easting and Northing coordinates
  • Census lookup areas
  • Rural Indicator
  • Broadband coverage data
  • Which (if any) national park the postcode is in


The R tools used in this code are

  1. Importing both .csv and tab delimited files into R
  2. Keeping and Renaming columns
  3. Removing spaces from the postcodes ready to merge the data
  4. Concatenating two data frames of the same format
  5. Removing unneeded data frames
  6. Merging data frames
  7. Outputting a data frame to .csv

I will hopefully get onto analysing this data at some point. Here is the code used to create the postcode file:

A copy of the final output can be downloaded from here.

Leave a Reply

Your email address will not be published. Required fields are marked *