
Last chance! 50% off unlimited learning
Sale ends in
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)
a vector of numeric, character, or factor values
a vector of numeric, character, or factor values
logical, does the order of values matter to pairing, default = FALSE
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
od_oneway
Other od:
dist_google()
,
od2line()
,
od2odf()
,
od_aggregate_from()
,
od_aggregate_to()
,
od_aggregate()
,
od_coords2line()
,
od_coords()
,
od_dist()
,
od_oneway()
,
od_radiation()
,
od_to_odmatrix()
,
odmatrix_to_od()
,
points2flow()
,
points2odf()
,
sp_aggregate()
# NOT RUN {
(d <- od_data_sample[2:9, 1:2])
(id <- od_id_character(d[[1]], d[[2]]))
duplicated(id)
od_id_szudzik(d[[1]], d[[2]])
od_id_max_min(d[[1]], d[[2]])
n <- 100
ids <- as.character(runif(n, 1e4, 1e7 - 1))
# benchmark of methods:
x <- data.frame(
id1 = rep(ids, times = n),
id2 = rep(ids, each = n),
val = 1,
stringsAsFactors = FALSE
)
bench::mark(check = FALSE, iterations = 10,
od_id_order(x),
od_id_character(x$id1, x$id2),
od_id_szudzik(x$id1, x$id2),
od_id_max_min(x$id1, x$id2)
)
# }
Run the code above in your browser using DataLab