View source: R/get_stop_frequency.R
| get_stop_frequency | R Documentation |
Returns the number of departures and the mean headway at each specified
stop_id within a given time of day, by service_id. Optionally, the
departures can also be counted by route_id (and by direction_id, if the
field is present in the trips table).
get_stop_frequency(gtfs, stop_id = NULL, from, to, by_route = FALSE)
gtfs |
A GTFS object, as created by |
stop_id |
A character vector including the |
from |
A string. The starting point of the time of day, in the "HH:MM:SS" format. |
to |
A string. The ending point of the time of day, in the "HH:MM:SS"
format. Must be later than |
by_route |
A logical. Whether the departures should be counted by
|
A data.table with the columns stop_id, route_id and
direction_id (only if by_route is TRUE, the latter only if present
in the trips table), service_id, departures (the number of
departures from the stop within the time of day, including each departure
generated from the frequencies table) and mean_headway (the mean
headway within the time of day, in minutes). Stops with no departures
within the time of day are not included.
The function counts stop departures: each stop_times entry with a
departure time is a departure from its stop, except for the entry of the
last stop of each trip (the one with the highest stop_sequence), from which
vehicles don't depart. Entries with blank departure times (such as those of
stops that are not timepoints) are not counted, so their times should be
interpolated beforehand to count them. A stop visited twice by the same trip
is counted twice. Its results are therefore not comparable to those of
get_route_frequency(), which counts trips.
The stop_times entries of trips listed in the frequencies table are just
templates: these trips depart every headway_secs from start_time until
(but not including) end_time, and each of these departures visits the
template's stops with the times shifted accordingly, as in
frequencies_to_stop_times(). Trips without any departure time in
stop_times don't generate departures. An error is raised if the
frequencies table has invalid entries for the trips that serve the
specified stops, even if they don't have any departure time.
The stops are those listed in stop_times, which are never stations. Use
get_children_stops() to get the stops of a station and sum their
departures.
A departure is counted when it happens at or after from and before to, so
that consecutive time windows (e.g. "06:00:00"-"07:00:00" and
"07:00:00"-"08:00:00") don't count the same departure twice. Please note
that this differs from filter_by_time_of_day(), which keeps entries whose
times are equal to to. Departures after midnight are listed with times
greater than "24:00:00" and belong to the previous service day, so a time
of day such as "24:00:00"-"26:00:00" should be used to account for them.
The mean headway is the length of the time of day divided by the number of
departures. It is an average over the whole time of day, so it is larger
than the actual headway when service starts or ends within it. Trips with an
NA direction_id are grouped together.
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
stop_frequency <- get_stop_frequency(
gtfs,
from = "07:00:00",
to = "09:00:00"
)
head(stop_frequency)
stop_ids <- c("18848", "18960")
stop_frequency <- get_stop_frequency(
gtfs,
stop_id = stop_ids,
from = "07:00:00",
to = "09:00:00",
by_route = TRUE
)
stop_frequency
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.