Learn R Programming

gtfstools (version 1.1.0)

filter_by_stop_id: Filter GTFS object by stop_id

Description

Filters a GTFS object by stop_ids, keeping (or dropping) relevant entries in each file. In order to keep the integrity of trips as described in the stop_times table, the stop_ids are actually used to filter trip_ids, which are then used to filter the rest of the GTFS object.

Usage

filter_by_stop_id(gtfs, stop_id, keep = TRUE)

Value

The GTFS object passed to the gtfs parameter, after the filtering process.

Arguments

gtfs

A GTFS object, as created by read_gtfs().

stop_id

A character vector. The stop_ids used to filter the data.

keep

A logical. Whether the entries related to the trip_ids that passes through the specified stop_ids should be kept or dropped (defaults to TRUE, which keeps the entries).

See Also

Other filtering functions: filter_by_agency_id(), filter_by_route_id(), filter_by_route_type(), filter_by_service_id(), filter_by_sf(), filter_by_shape_id(), filter_by_time_of_day(), filter_by_trip_id(), filter_by_weekday()

Examples

Run this code
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
stop_ids <- c("18848", "940004157")

object.size(gtfs)

# keeps entries related to trips that pass through specified stop_ids
smaller_gtfs <- filter_by_stop_id(gtfs, stop_ids)
object.size(smaller_gtfs)

# drops entries related to trips that pass through specified stop_ids
smaller_gtfs <- filter_by_stop_id(gtfs, stop_ids, keep = FALSE)
object.size(smaller_gtfs)

Run the code above in your browser using DataLab