Combine two ID values to create a single ID number

od_id_szudzik(x, y, ordermatters = FALSE)

od_id_max_min(x, y)

od_id_character(x, y)

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

od_oneway

Other od: od_to_odmatrix(), odmatrix_to_od()

Examples

(d = od_data_df[2:9, 1:2])
#>      geo_code1 geo_code2
#> 2    E02002404 E02006875
#> 3    E02006875 E02006875
#> 4    E02006876 E02006875
#> 5    E02006861 E02002392
#> 6    E02006875 E02002392
#> 7    E02002392 E02006875
#> NA        <NA>      <NA>
#> NA.1      <NA>      <NA>
(id = od_id_character(d[[1]], d[[2]]))
#> [1] "E02002404 E02006875" "E02006875 E02006875" "E02006875 E02006876"
#> [4] "E02002392 E02006861" "E02002392 E02006875" "E02002392 E02006875"
#> [7] "NA NA"               "NA NA"              
duplicated(id)
#> [1] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE
od_id_szudzik(d[[1]], d[[2]])
#> [1]  5  6 11 29 27 27 NA NA
od_id_max_min(d[[1]], d[[2]])
#> [1]  4  5  8 19 17 17 NA NA