R/haversine.dist.R

Defines functions haversine.dist

Documented in haversine.dist

haversine.dist <- function(x) {
  Rfast::Dist(x, method = "haversine")
}



# haversine.dist <- function(x) {
#   n <- dim(x)[1]
#   mat <- matrix(0, nrow = n, ncol = n)
#   x1 <- x[, 1]
#   x2 <- x[, 2]
#   for (i in 1:(n - 1) )  {
#     ind <- (i + 1):n
#     ind_row <- x1[ind]
#     a <- sin( 0.5 * (x1[i] - ind_row) )^2 + cos(x1[i]) * cos(ind_row) * sin( 0.5 * (x2[i] - x2[ind]) )^2
#     mat[i, ind] <- mat[ind, i] <- 2 * asin( sqrt(a) )
#   }
#
#   mat
# }

Try the Directional package in your browser

Any scripts or data that you put into this service are public.

Directional documentation built on Oct. 12, 2023, 1:07 a.m.