get_headways: Calculate Headways in GTFS Data

View source: R/get_headways.R

get_headwaysR Documentation

Calculate Headways in GTFS Data

Description

The 'get_headways' function calculates headways within a 'wizardgtfs' object using different methods. Depending on the selected 'method', it can provide average headways by route, by trip, by hour, or detailed stop-level headways.

Usage

get_headways(gtfs, method = "by.route")

Arguments

gtfs

A GTFS object, ideally of class 'wizardgtfs'. If not, it will be converted.

method

A character string specifying the calculation method. Options include:

"by.route"

Calculates the average headway for each route, assuming constant headways along stops.

"by.hour"

Calculates the hourly headway for each route, assuming constant headways along stops.

"by.trip"

Calculates headways for each trip, assuming constant headways along stops.

"by.stop"

Calculates headways for each stop.

"by.shape"

Calculates headways for each shape

"detailed"

Calculates detailed headways between consecutive stops within each route and trip.

Details

This function calls specific sub-functions based on the selected method:

- "by.route": Calculates the average headway for each route based on the first stop time per trip.

- "by.hour": Calculates the hourly headway for each route, grouping trips by hour.

- "by.trip": Calculates headways for each trip, considering only the first stop time.

- "by.stop": Calculates headways for each stop.

- "by.shape": Calculates headways for each shape.

- "detailed": Provides headway calculations for each consecutive stop within each trip.

If an invalid 'method' is specified, the function defaults to '"by.route"' and provides a warning.

Value

A data frame containing service headways based on the specified method:

If 'method = "by.route"'

Returns a data frame with columns: 'route_id', 'valid_trips', 'average_headway', 'service_pattern', and 'pattern_frequency'.

If 'method = "by.hour"'

Returns a data frame with columns: 'hour', 'valid_trips', 'average_headway', 'service_pattern', and 'pattern_frequency'.

If 'method = "by.trip"'

Returns a data frame with columns: 'route_id', 'trip_id', 'headway', 'service_pattern', and 'pattern_frequency'.

If 'method = "by.stop"'

Returns a data frame with columns: 'stop_id', 'direction_id', 'valid_trips', 'headway', 'service_pattern', and 'pattern_frequency'.

If 'method = "by.shape"'

Returns a data frame with columns: 'shape_id', 'direction_id', 'valid_trips', 'headway', 'service_pattern', and 'pattern_frequency'.

If 'method = "detailed"'

Returns a data frame with columns: 'route_id', 'trip_id', 'stop_id', 'hour', 'headway', 'service_pattern', and 'pattern_frequency'.

See Also

[GTFSwizard::as_wizardgtfs()], [GTFSwizard::get_servicepattern()]

Examples

# Calculate average route headways
headways_by_route <- get_headways(gtfs = for_rail_gtfs, method = "by.route")

# Calculate hourly headways
headways_by_hour <- get_headways(gtfs = for_rail_gtfs, method = "by.hour")

# Calculate headways for each trip
headways_by_trip <- get_headways(gtfs = for_rail_gtfs, method = "by.trip")

# Calculate headways for each stop
headways_by_stop <- get_headways(gtfs = for_rail_gtfs, method = "by.stop")

# Calculate headways for each shape
headways_by_shape <- get_headways(gtfs = for_rail_gtfs, method = "by.shape")

# Calculate detailed stop-level headways
detailed_headways <- get_headways(gtfs = for_rail_gtfs, method = "detailed")


GTFSwizard documentation built on April 4, 2025, 4:10 a.m.