Combine two ID values to create a single ID number
Arguments
- x
a vector of numeric, character, or factor values
- y
a vector of numeric, character, or factor values
- ordermatters
logical, does the order of values matter to pairing, default = FALSE
Details
In OD data it is common to have many 'oneway' flows from "A to B" and "B to A". It can be useful to group these an have a single ID that represents pairs of IDs with or without directionality, so they contain 'twoway' or bi-directional values.
od_id*
functions take two vectors of equal length and return a vector of IDs,
which are unique for each combination but the same for twoway flows.
the Szudzik pairing function, on two vectors of equal length. It returns a vector of ID numbers.
This function superseeds od_id_order as it is faster on large datasets
See also
Other od:
od2line()
,
od2odf()
,
od_aggregate_from()
,
od_aggregate_to()
,
od_coords2line()
,
od_coords()
,
od_id_order()
,
od_oneway()
,
od_to_odmatrix()
,
odmatrix_to_od()
,
points2flow()
,
points2odf()
Examples
(d <- od_data_sample[2:9, 1:2])
#> # A tibble: 8 × 2
#> geo_code1 geo_code2
#> <chr> <chr>
#> 1 E02002361 E02002363
#> 2 E02002361 E02002367
#> 3 E02002361 E02002371
#> 4 E02002361 E02002377
#> 5 E02002361 E02002382
#> 6 E02002361 E02002384
#> 7 E02002361 E02002393
#> 8 E02002363 E02002361
(id <- od_id_character(d[[1]], d[[2]]))
#> [1] "E02002361 E02002363" "E02002361 E02002367" "E02002361 E02002371"
#> [4] "E02002361 E02002377" "E02002361 E02002382" "E02002361 E02002384"
#> [7] "E02002361 E02002393" "E02002361 E02002363"
duplicated(id)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
od_id_szudzik(d[[1]], d[[2]])
#> [1] 5 10 17 26 37 50 65 5
od_id_max_min(d[[1]], d[[2]])
#> [1] 4 7 11 16 22 29 37 4