| distances_from_graph | R Documentation |
Compute a distance matrix for all node pairs in a graph using igraph.
distances_from_graph(graph_df, directed = FALSE, cost.column = "cost", ...)
graph_df |
A data frame representing a graph with columns:
|
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 |
... |
Additional arguments passed to |
This function:
Converts the graph data frame to a igraph graph object
Contracts the graph for efficient distance computation
Computes the distance matrix for all node pairs using the specified algorithm
A matrix of distances between all node pairs, where rows and columns
correspond to node IDs. The matrix contains the shortest path distances
(based on the cost column) between all pairs of nodes.
library(flownet)
# Create a simple graph
graph <- data.frame(
from = c(1, 2, 2, 3),
to = c(2, 3, 4, 4),
cost = c(1, 2, 3, 1)
)
# Compute distance matrix
dmat <- distances_from_graph(graph, cost.column = "cost")
dmat
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.