Learn R Programming

stplanr (version 0.1.4)

onewayid: Aggregate ods so they become non-directional, e.g. by summing travel in both directions.

Description

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 (see flowlines) which can be confusing for users and are difficult to plot.

Usage

onewayid(x, attrib, id1 = names(x)[1], id2 = names(x)[2])

Arguments

x
A data frame, representing an OD matrix
attrib
A vector of column numbers or names for deciding which attribute(s) of class numeric to aggregate
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

Value

onewayid outputs a data.frame with rows containing results for the user-selected attribute values that have been aggregated.

Details

This function aggregates directional flows into non-directional flows, potentially halving the number of lines objects and reducing the number of overlapping lines to zero.

Examples

Run this code
data("flow")
flow_oneway = onewayid(flow, attrib = 3)
nrow(flow_oneway) < nrow(flow) # result has fewer rows
sum(flow$All) == sum(flow_oneway$All) # but the same total flow
# using names instead of index for attribute
onewayid(flow, attrib = "All")
# using many attributes to aggregate
attrib = which(vapply(flow, is.numeric, TRUE))
flow_oneway = onewayid(flow, attrib = attrib)
colSums(flow_oneway[attrib]) == colSums(flow[attrib]) # test if the colSums are equal
# Demonstrate the results from onewayid and onewaygeo are identical
flow_oneway_geo = onewaygeo(flowlines, attrib = attrib)
plot(flow_oneway$All, flow_oneway_geo$All)

Run the code above in your browser using DataLab