Calculate speed (m/s) based on geodesic distance with longitude, latitude, date-time input vectors. The unit of speed is metres per second.

track_speed(x, y, date)

Arguments

x

longitude

y

latitude

date

date-time in POSIXct

Value

numeric vector of sequential distances in metres per second, see Details

Details

By convention the first value is set to NA missing value, because the difference 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(speed = track_speed(lon, lat, date))

Examples

track_speed(trips0$x, trips0$y, trips0$date)[1:10]
#>  [1]        NA 13.737516  3.461082 30.425255  6.047975 14.614121  2.964696
#>  [8]  9.263687  9.522909  9.267413