For example, sum total travel in both directions.

od_oneway(
  x,
  attrib = names(x[-c(1:2)])[vapply(x[-c(1:2)], is.numeric, TRUE)],
  FUN = sum,
  ...,
  id1 = names(x)[1],
  id2 = names(x)[2],
  oneway_key = NULL
)

Arguments

x

A data frame or SpatialLinesDataFrame, representing an OD matrix

attrib

A vector of column numbers or names, representing variables to be aggregated. By default, all numeric variables are selected.

FUN

The aggregating function such as sum (the default) and mean

...

Further arguments passed to or used by methods

id1

Optional (it is assumed to be the first column) text string referring to the name of the variable containing the unique id of the origin

id2

Optional (it is assumed to be the second column) text string referring to the name of the variable containing the unique id of the destination

oneway_key

Optional key of unique OD pairs regardless of the order, e.g., as generated by od_id_max_min() or od_id_szudzik()

Value

oneway outputs a data frame (or sf data frame) with rows containing results for the user-selected attribute values that have been aggregated.

Details

Flow data often contains movement in two directions: from point A to point B and then from B to A. This can be problematic for transport planning, because the magnitude of flow along a route can be masked by flows the other direction. If only the largest flow in either direction is captured in an analysis, for example, the true extent of travel will by heavily under-estimated for OD pairs which have similar amounts of travel in both directions. Flows in both direction are often represented by overlapping lines with identical geometries which can be confusing for users and are difficult to plot.

Examples

(od_min = od_data_df[c(1, 2, 1), 1:4])
#>     geo_code1 geo_code2  all train
#> 1   E02002384 E02006875  966    14
#> 2   E02002404 E02006875 1145     6
#> 1.1 E02002384 E02006875  966    14
od_min[3, 1:2] = rev(od_min[3, 1:2])
od_min[3, 3:4] = od_min[3, 3:4] - 5
(od_oneway = od_oneway(od_min))
#>   geo_code1 geo_code2  all train
#> 1 E02002384 E02006875 1927    23
#> 2 E02002404 E02006875 1145     6
nrow(od_oneway) < nrow(od_min) # result has fewer rows
#> [1] TRUE
sum(od_min$all) == sum(od_oneway$all) # but the same total flow
#> [1] TRUE
(od_oneway = od_oneway(od_min, FUN = mean))
#>   geo_code1 geo_code2    all train
#> 1 E02002384 E02006875  963.5  11.5
#> 2 E02002404 E02006875 1145.0   6.0
od_oneway(od_min, attrib = "all")
#>   geo_code1 geo_code2  all
#> 1 E02002384 E02006875 1927
#> 2 E02002404 E02006875 1145
od_min$all[3] = NA
(od_oneway = od_oneway(od_min, FUN = mean, na.rm = TRUE))
#>   geo_code1 geo_code2  all train
#> 1 E02002384 E02006875  966  11.5
#> 2 E02002404 E02006875 1145   6.0