Learn R Programming

tidytransit (version 1.7.0)

stop_group_distances: Calculates distances among stop within the same group column

Description

By default calculates distances among stop_ids with the same stop_name.

Usage

stop_group_distances(gtfs_stops, by = "stop_name")

Value

data.frame with one row per group containing a distance matrix (distances), number of stop ids within that group (n_stop_ids) and distance summary values (dist_mean, dist_median and dist_max).

Arguments

gtfs_stops

gtfs stops table either as data frame (with at least stop_id, stop_lon and stop_lat columns) or as sf object.

by

group column, default: "stop_name"

Examples

Run this code
if (FALSE) {
library(dplyr)

nyc_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
nyc <- read_gtfs(nyc_path)

stop_group_distances(nyc$stops)
#> # A tibble: 380 × 6
#>    stop_name   distances       n_stop_ids dist_mean dist_median dist_max
#>                                          
#>  1 86 St                18     5395.       5395.   21811.
#>  2 79 St                   6    19053.      19053.   19053.
#>  3 Prospect Av             6    18804.      18804.   18804.
#>  4 77 St                   6    16947.      16947.   16947.
#>  5 59 St                   6    14130.      14130.   14130.
#>  6 50 St                   9     7097.       7097.   14068.
#>  7 36 St                   6    12496.      12496.   12496.
#>  8 8 Av                    6    11682.      11682.   11682.
#>  9 7 Av                    9     5479.       5479.   10753.
#> 10 111 St                  9     3877.       3877.    7753.
#> # … with 370 more rows
}

Run the code above in your browser using DataLab