distance_matrix: Convert Long-Format Distance Tibble to Matrix

View source: R/clustering.R

distance_matrixR Documentation

Convert Long-Format Distance Tibble to Matrix

Description

Convert Long-Format Distance Tibble to Matrix

Usage

distance_matrix(distances, distance_col = "fds")

Arguments

distances

tibble with columns flow_ID_a, flow_ID_b, and distance

distance_col

column name for distance (default "fds")

Value

distance matrix (tibble with rownames). The matrix has flow_ID_a as rownames and flow_ID_b as column names. This function converts the output of flow_distance() into a format suitable for the dbscan clustering algorithm.

Examples

flows <- sf::st_transform(flows_leeds, 3857)
flows <- head(flows, 100) # for testing
# Add flow lengths and coordinates
flows <- add_flow_length(flows)
flows <- add_xyuv(flows)
# Calculate distances
distances <- flow_distance(flows, alpha = 1.5, beta = 0.5)
dmat <- distance_matrix(distances)

flowcluster documentation built on Aug. 21, 2025, 5:54 p.m.