Skip to contents

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.

Usage

distance_between(a, b, origin = "country.name")

Arguments

a, b

Vectors of country names or codes (recycled against each other).

origin

How to read a/b (default "country.name").

Value

A numeric vector of great-circle distances in kilometres (NA for any country that doesn't resolve to a known centroid).

Examples

distance_between("France", "Germany")
#> [1] 802.3524
distance_between("USA", c("Canada", "Mexico"))
#> [1] 2184.930 1622.586