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

adherence_area(zipcode)

Arguments

zipcode

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

Value

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

Details

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

The following hospitals and their zipcodes are hard-coded:

HospitalZip Code
Antonius8601
Frisius Heerenveen8441
Frisius Leeuwarden8934
Martini9728
Nij Smellinghe9202
Ommelander9679
Treant7824
Wilhelmina9401

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("plot2", quietly = TRUE)) {
  library(certeplot2)
  geo_postcodes4 |>
     crop_certe() |>
     plot2(category = suppressMessages(adherence_area(postcode)),
           datalabels = FALSE) |>
     add_sf(geo_provincies |> crop_certe(),
            colour_fill = NA, colour = "black", linewidth = 0.5)
}