Haversine distance (km) between two countries' centroids – the lightweight
companion to country_borders() for "how far apart" rather than "do they
touch". Works from the bundled country_meta centroids, so unlike most of
the spatial toolkit it needs neither sf nor the network.
Value
A numeric vector of great-circle distances in kilometres (NA for
any country that doesn't resolve to a known centroid).
Countries without a bundled centroid
country_meta carries no centroid for a handful of small or dependent
territories (Bouvet Island, the British Virgin Islands, Gibraltar, Hong Kong,
Macao, Svalbard and Jan Mayen, Tokelau, Tuvalu, the U.S. Minor Outlying
Islands and the Aland Islands), and no row at all for Kosovo, because
countrycode::codelist has none. Those inputs return NA here even though
the geometry backends do map them – so neighbors() and country_borders()
know about Kosovo while this function does not.
Examples
distance_between("France", "Germany")
#> [1] 802.3524
distance_between("USA", c("Canada", "Mexico"))
#> [1] 2184.930 1622.586
