I\'m using the igraph
package in R to do something rather simple: Calculate the shortest distance between two nodes in my network. Is there a straightforward w
You can use shortest.paths
function,
e.g.:
# compute the min distances from '234' to all other vertices
tmp3 <- shortest.paths(g2,v='234',weights=E(g2)$newcost)
# print min distance from '234' to '245'
tmp3[1, which(V(g2)$name == '245')]
The distance computed by the algorithm is 34.5 = 11 + 8.2 + 15.3
, as shown in the following picture: