I have a data frame with data about a driver and the route they followed. I\'m trying to figure out the total mileage traveled. I\'m using the geosphere
packa
How about this?
## Setup
library(geosphere)
metersPerMile <- 1609.34
pts <- df1[c("lon", "lat")]
## Pass in two derived data.frames that are lagged by one point
segDists <- distVincentyEllipsoid(p1 = pts[-nrow(df),],
p2 = pts[-1,])
sum(segDists)/metersPerMile
# [1] 1013.919
(To use one of the faster distance calculation algorithms, just substitute distCosine
, distVincentySphere
, or distHaversine
for distVincentyEllipsoid
in the call above.)