View source: R/get_trip_speed.R
| get_trip_speed | R Documentation |
Returns the average speed of each specified trip_id, either from the first
to the last stop of the trip or between each pair of consecutive stops.
get_trip_speed(
gtfs,
trip_id = NULL,
method = "shapes",
by = "trip",
unit = "km/h",
sort_sequence,
file = NULL,
from = NULL,
to = NULL
)
gtfs |
A GTFS object, as created by |
trip_id |
A character vector including the |
method |
A string, either |
by |
A string, either |
unit |
A string representing the unit in which the speeds are desired.
One of |
sort_sequence |
Deprecated; do not supply. Timetables and shapes are
now always sorted by |
file |
Deprecated. Use |
from |
A string, in the "HH:MM:SS" format. With |
to |
A string, in the "HH:MM:SS" format. Only trips (or segments) that
depart from their first stop at or before |
With by = "trip", a data.table with the route_id, the
trip_id and the average speed of each trip. With by = "segment", a
data.table with the route_id, the trip_id, the segment number, the
from_stop_id and to_stop_id that delimit the segment and its average
speed.
The speed is the length calculated by get_trip_length() divided by the
duration calculated by get_trip_duration() (with by = "trip") or by
get_trip_segment_duration() (with by = "segment"). Speeds are NA when
the length is NA (e.g. trips not linked to a shape) or when the duration
is missing (e.g. blank times at intermediate stops) or not positive. With
by = "trip", trips without any arrival or departure time raise the warning
of get_trip_duration().
The route_id of each trip comes from the trips table, which is required
(also with method = "euclidean"). Trips not listed in trips have an NA
route_id.
Existing _secs columns in stop_times (e.g. created with
convert_time_to_seconds()) are used as-is, not recalculated from the time
strings.
from and to select the trips (or segments) as in get_trip_length(),
from the departure_time strings, even if _secs columns exist.
get_route_speed(), set_trip_speed(), set_route_speed(),
get_trip_length(), get_trip_duration(), get_trip_segment_duration()
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
trip_speed <- get_trip_speed(gtfs)
head(trip_speed)
trip_ids <- c("CPTM L07-0", "2002-10-0")
trip_speed <- get_trip_speed(gtfs, trip_ids)
trip_speed
trip_speed <- get_trip_speed(gtfs, trip_ids, method = "euclidean")
trip_speed
trip_speed <- get_trip_speed(gtfs, trip_ids, unit = "m/s")
trip_speed
segment_speed <- get_trip_speed(gtfs, "CPTM L07-0", by = "segment")
head(segment_speed)
# speed of the trips that depart within a time of day
peak_speed <- get_trip_speed(gtfs, from = "07:00:00", to = "09:00:00")
head(peak_speed)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.