get_speeds {GTFSwizard} | R Documentation |
Calculate Speeds for GTFS Routes and Trips
Description
'get_speeds' calculates the average speed of trips and routes within a 'wizardgtfs' object. It uses distance and duration to provide speed outputs based on the specified 'method'.
Usage
get_speeds(gtfs, method = "by.route", trips = "all")
Arguments
gtfs |
A GTFS object, ideally of class 'wizardgtfs'. If the 'shapes' table is missing, it will be created automatically using 'get_shapes()'. |
method |
A character string specifying the calculation method. Options include:
|
trips |
A character vector of trip IDs to consider. When set to 'all', includes all trips. |
Details
- This function calls specific sub-functions based on the selected 'method':
- 'by.route'
Calculates average speed across each route.
- 'by.trip'
Calculates average speed across each trip.
- 'detailed'
Calculates speeds between consecutive stops within each trip.
- If an invalid 'method' is specified, the function defaults to '"by.route"' and provides a warning.
Value
A data frame containing speed calculations, depending on the specified method:
- If 'method = "by.route"'
Returns a data frame with columns: 'route_id', 'trips', 'average.speed', 'service_pattern', and 'pattern_frequency'.
- If 'method = "by.trip"'
Returns a data frame with columns: 'route_id', 'trip_id', 'average.speed', 'service_pattern', and 'pattern_frequency'.
- If 'method = "detailed"'
Returns a data frame with columns: 'route_id', 'trip_id', 'hour', 'from_stop_id', 'to_stop_id', 'speed', 'service_pattern', and 'pattern_frequency'.
See Also
[GTFSwizard::get_distances()], [GTFSwizard::get_durations()], [GTFSwizard::get_shapes()]
Examples
# Calculate average route speeds
speeds_by_route <- get_speeds(gtfs = for_rail_gtfs, method = "by.route", trips = 'all')
# Calculate trip speeds
speeds_by_trip <- get_speeds(gtfs = for_rail_gtfs, method = "by.trip", trips = 'all')
# Calculate detailed speeds between stops
detailed_speeds <- get_speeds(gtfs = for_rail_gtfs, method = "detailed", trips = 'all')