n <- 50
# Default "cheap" distance measure is only accurate for short distances:
x <- cbind (runif (n, -0.1, 0.1), runif (n, -0.1, 0.1))
y <- cbind (runif (2 * n, -0.1, 0.1), runif (2 * n, -0.1, 0.1))
colnames (x) <- colnames (y) <- c ("x", "y")
index <- geodist_min (x, y, measure = "Haversine")
# 'index' is a vector of 50 values indexing elements of `y` corresponding to
# minimal distances to each element of `x`. It is exactly the same as the
# value returned by these lines:
d0 <- geodist (x, y, measure = "Haversine")
index0 <- apply (d0, 1, which.min)
identical (index, index0)
Run the code above in your browser using DataLab