8 Finding the Time to Complete a Particular Stretch
In order to compare the time it takes two or more drivers to cover the same stretch of a stage route, we need to find out how long it takes each of them to cover that distance.
The following function will chunk the route into fixed length segments (exempt the final segment) and find out how long it takes the driver to complete that section.
# Return time to travel along a segment.
# Units relate to whether the distances are in eg m or km
= function(driver_estimator, cumdist,
segmentTimeDelta stretch=100, units='m'){
driver_estimator(cumdist+stretch) - driver_estimator(cumdist)
}
We can now generate a simple estimate of the time taken to complete each segment:
#18163.4 %/% 1000 -> 18
# Get sections 1000m long
= 1000
segment_length
#units = 'm'
#segment_length_m = set_units(segment_length, m)
= seq(from=0, to=stage_length, by = segment_length)
segments
= segmentTimeDelta(evans_time_estimator,
evans_1km_segments
segments, segment_length) evans_1km_segments
## [1] 37.58843 26.93338 28.29342 26.21198 30.94418 24.63189 27.20249 31.85834
## [9] 32.99157 25.37383 36.76296 27.10636 28.68083 20.69407 20.13347 31.38227
## [17] 26.35240 NA NA
Let’s also grab similar estimates for another driver:
= segmentTimeDelta(fourmaux_time_estimator,
fourmaux_1km_segments
segments, segment_length) fourmaux_1km_segments
## [1] 35.36710 28.22918 28.49147 27.66114 31.34492 26.23118 29.05474 32.60108
## [9] 34.48317 31.58292 32.36769 27.78844 27.56022 25.43212 25.43212 25.43212
## [17] 25.43212 25.43212 NA