The NHS Postcode Directory is a database of all of the Postcodes within the United Kingdom, along with the codes for things like CCG, STP, Local Authority for which that postcode belongs to. Unfortunately, the raw csv's do not have any column headings, so it's pretty difficult to use.
nhspd_load( file = dir(path, "^nhg.*\\.csv$", full.names = TRUE), path = "./Data" )
file | the file to load, defaults to a file that begins with "nhg" in the folder "path" |
---|---|
path | the path where the file is stored. Defaults to "Data" in the current directory. Change this to where you saved the downloaded files, or set "." for the current directory |
This script will handle loading of the csv by adding in the correct column headings and datatypes for those columns.
Instructions for use -----
Download from https://geoportal.statistics.gov.uk the latest NHSPD file. This is found under the "Postcodes"->"NHS Postcode Directory (NHSPD)" menu.
Download the "NHS Postcode Directory UK Full" version, and not the extract version.
Unzip the contents of the download and update the "path" variable to point to the correct location (alternatively, extract the zip contents to your current R working directory: you can view this folder easily by clicking the "More" button in the R-Studio Files pane and selecting "Show folder in new window").
Inside the folder there are a number of directories. If you look at the word document inside of the "Contents" folder this will explain the structure of the NHSPD. The "User Guide" is also very useful as it explains what each of the columns contains.
NOTE: loading the complete csv will use up a large amount of RAM, (the Nov-19 version used 2.3 GB of RAM on my machine). You may wish to use one of the regional files (see the Contents folder to figure out which to use), or you may wish to consider altering the column types to skip columns that you are not interested in. To do this, change the col type for that column to be col_skip().