Looks up the nearest reference name for a given zipcode (4 digits) based on the shortest distance in the postcodes4_afstanden dataset.

adherence_area(
  zipcode,
  reference = c(Antonius = "8601", `Frisius Heerenveen` = "8441", `Frisius Leeuwarden` =
    "8934", Martini = "9728", `Nij Smellinghe` = "9202", Ommelander = "9679", Treant =
    "7824", Wilhelmina = "9401")
)

Arguments

zipcode

A character or numeric vector of zipcodes. Six-character zipcodes are automatically truncated to the first 4 digits using substr().

reference

A character vector of zipcodes to use as reference, preferably named. Defaults to hospitals in the region.

Value

A character vector of names of reference, the same length as zipcode.

Details

The function looks up the distance from each input zipcode to all zipcodes of reference in postcodes4_afstanden. The names with the shortest distance is returned. In case of equal distances, the first name in definition order is chosen.

Zipcodes not found in postcodes4_afstanden return NA.

Examples

adherence_area("9700")
#> Interpreting missing 9700 as closest higher 9711
#> [1] "Martini"
adherence_area(c("9713", "7702", "8896"))
#> [1] "Martini"            "Treant"             "Frisius Leeuwarden"

# six-character zipcodes are automatically truncated
adherence_area("9251AB")
#> [1] "Frisius Leeuwarden"

if (requireNamespace("certeplot2", quietly = TRUE)) {
  geo_postcodes4 |>
     crop_certe() |>
     plot2(category = suppressMessages(adherence_area(postcode)),
           datalabels = FALSE) |>
     plot2::add_sf(geo_provincies |> crop_certe(),
            colour_fill = NA, colour = "black", linewidth = 0.5)
}


if (requireNamespace("certeplot2", quietly = TRUE)) {
  hospitals <- c("Antonius"           = "8601",
                 "Frisius Heerenveen" = "8441",
                 "Frisius Leeuwarden" = "8934",
                 "Martini"            = "9728",
                 "Nij Smellinghe"     = "9202",
                 "Ommelander"         = "9679",
                 "Treant"             = "7824",
                 "Wilhelmina"         = "9401")
  zip4 <- geo_postcodes4 |> crop_certe()

  zip4 |>
    plot2(category = adherence_area(postcode, reference = hospitals),
          datalabels = FALSE) |>
    plot2::add_sf(geo_provincies |> crop_certe(),
           colour_fill = "#FFFFFF77", colour = "black", linewidth = 0.5) |>
    plot2::add_sf(zip_to_sf(hospitals),
           datalabels = names(hospitals),
           colour = "black")
}