Description Usage Arguments Details Value Note Author(s) Source Examples
Convenient function to look up Townsend deprivation scores using UK postcodes, postcode prefixes, postcode suffixes or a regular expression.
1 |
postcode |
A vector of UK postcodes, postcode prefixes, postcode suffixes, or a regular expression. |
type |
A character string indicating the term provided in the |
"full"
— a full five–seven character postcode.
"prefix"
— a two–four character postcode prefix.
"suffix"
— a three character postcode suffix.
"regex"
— a regular expression, allowing any nature of postcode match.
squash |
a logical parameter indicating whether the scores returned should be aggregated into a single median value. |
getTDS
is a lookup function that queries a dataset of postcodes and Townsend deprivation scores.
This dataset was created by joining a dataset of postcodes to a dataset of Townsend deprivation scores, via output area codes.
Both data sets are made available by the Office for National Statistics under the Open Government License.
The postcode dataset was last updated in February 2019, while the dataset of Townsend deprivation scores uses values obtained from the 2011 UK census (matching the Townsend deprivation score dates used by ClinRisk in the derivation of the QDiabetes-2018 algorithms).
Townsend Deprivation Score.
Where type
is not set to "regex"
, the length and nature of the value returned are governed by the type
and squash
parameters:
When squash
is set to FALSE
(the default value) an output vector will be returned that is of equal length to the input vector. When squash
is set to TRUE
a numeric output of length one will be returned, comprising the median Townsend deprivation score from all matched postcodes.
As each postcode is only associated with a single output area, when type
is set to "full"
and squash
is set to FALSE
the Townsend deprivation scores returned will be the exact values associated with each linked output area.
As each postcode prefix or suffix may be associated with multiple output areas, when squash
is set to FALSE
and type
is set to "prefix"
or "suffix"
the median Townsend deprivation score per prefix/suffix will be returned.
PO Box codes have no associated Townsend deprivation scores and will not work as function inputs.
No Northern Ireland postcodes are present in the database searched by getTDS
as their use is governed by a separate, more restrictive license.
Contains OS data (C) Crown copyright and database right 2020
Contains Royal Mail data (C) Royal Mail copyright and database right 2020
Source: Office for National Statistics licensed under the Open Government Licence v.3.0
Benjamin G. Feakins benjamin.feakins@ndph.ox.ac.uk
UK Postcode-to-output-area data were obtained here from the Office for National Statistics.
Output-area-to-Townsend-deprivation-scores data were obtained here from the Office for National Statistics.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## Simple usage
getTDS(postcode = "OX2 6GG")
getTDS(postcode = c("OX2 6NW", "OX3 7LF"))
## Case & white space insensitive
getTDS(postcode = c("OX37LF", "OX3 7LF", "ox37lf", "ox3 7lf"))
## Median Townsend Deprivaton Score per Postcode Prefix ##
getTDS(postcode = paste0("OX", 1:9), type = "prefix")
## Median Overall Townsend Deprivation Score for a Set of Prefixes ##
getTDS(postcode = paste0("OX", 1:9), type = "prefix", squash = TRUE)
## Median Townsend Deprivaton Score per Postcode Suffix ##
getTDS(postcode = paste0(1:9, "AA"), type = "suffix")
## Median Overall Townsend Deprivation Score for a Set of Prefixes ##
getTDS(postcode = paste0(1:9, "AA"), type = "suffix", squash = TRUE)
## Median Overall Townsend Deprivation Score for Postcodes Matching a Regular Expression ##
getTDS(postcode = "^OX37[A-Z]{2}$", type = "regex")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.