решение с использованием sf
-пакета
образец данных
library(data.table)
dt1 <- data.table::fread( 'DateTime, Latitude, Longitude
2018-06-18 03:01:00, -2.434901, 34.85359
2018-06-18 03:06:00, -2.434598, 34.85387
2018-06-18 03:08:00, -2.434726, 34.85382
2018-06-18 03:12:00, -2.434816, 34.85371
2018-06-18 03:16:00, -2.434613, 34.85372
2018-06-18 03:20:00, -2.434511, 34.85376')
setDF(dt1)
код
library(sf)
#create spatial points object
dt1.sf <- st_as_sf( x= dt1,
coords = c("Longitude", "Latitude"),
crs = "+proj=longlat +datum=WGS84")
#calculate distances
st_distance(dt1.sf)
выход
# Units: [m]
# [,1] [,2] [,3] [,4] [,5] [,6]
# [1,] 0.00000 45.74224 32.07520 16.32379 34.97450 47.08749
# [2,] 45.74224 0.00000 15.20702 29.96245 16.76520 15.56348
# [3,] 32.07520 15.20702 0.00000 15.77068 16.72801 24.69270
# [4,] 16.32379 29.96245 15.77068 0.00000 22.47452 34.18116
# [5,] 34.97450 16.76520 16.72801 22.47452 0.00000 12.12446
# [6,] 47.08749 15.56348 24.69270 34.18116 12.12446 0.00000