Skip to contents

Add postcode variables e.g. Ward, to a data frame with postcodes

Usage

add_postcode_vars(
  df,
  pcd_name = "postcode",
  .admin_district = TRUE,
  .lat_long = FALSE,
  other_vars = character(0)
)

Arguments

df

data frame with a postcode variable

pcd_name

name of the postcode variable in passed the data frame

.admin_district

boolean indicating whether to add an admin_district variable

.lat_long

boolean indicating whether to add a pair of latitude & longitude variables

other_vars

character vector of other variables to add

Value

data frame with variables added based on postcode

Examples

# Create a data frame with some example records
df <- tibble::tribble(
  ~name,    ~postcode,
  "SCC",    "S1 2HH",
  "Blades", "S2 4SU",
  "Owls",   "S6 1SW"
)

add_postcode_vars(
  df,
  pcd_name = "postcode",
  .admin_district = FALSE,
  .lat_long = TRUE,
  other_vars = c("admin_ward", "msoa_code")
)