Calculate geodesic distance on longitude, latitude input vectors. The unit of distance is metres.

track_distance(x, y)

Arguments

x

longitude

y

latitude

Value

numeric vector of distances between sequential pairs of x, y in metres, see Details

Details

By convention the first value is set to NA missing value, because the distance applies to each sequential pair of locations.

To use this on multiple track ids, use a grouped data frame with tidyverse code like data %>% group_by(id) %>% mutate(distance = track_distance(lon, lat))

Examples

track_distance(trips0$x, trips0$y)[1:10]
#>  [1]        NA 129434.87  34631.59 120575.29  30560.42  97593.10  57005.17
#>  [8] 108811.27 130587.65  86066.46