Compute a distance matrix for all node pairs in a graph using igraph.
Arguments
- graph_df
A data frame representing a graph with columns:
from,to, and a cost column (seecost.column).- directed
Logical (default: FALSE). If TRUE, treats the graph as directed; if FALSE, treats it as undirected.
- cost.column
Character string (optional). Name of the cost column in
graph_df. Alternatively, a numeric vector of edge costs with length equal tonrow(graph_df).- ...
Additional arguments passed to
distances(), such asv(from) andtoto compute paths between specific nodes.
Value
A matrix of shortest path distances (based on the edge costs) between node pairs. Rows and columns are named by node ID, in ascending order of node ID.
Details
This function:
Converts the graph data frame to an igraph graph object, with the sorted unique node IDs as vertex names
Computes the shortest path distances with
distances(mode = "out"), by default for all node pairs
