title: Distance Matrix from second variable using get.shortest.paths()
body: <p>I would like to go one step further with this question (<a href="https://stackoverflow.com/questions/10740100/find-total-of-second-variable-related-to-the-distance-of-route-from-get-shortest">Find total of second variable related to the distance of route from get.shortest.paths()</a>). How does one get the matrix of distances between nodes, when the 'shortest' path is found using the newcost variable? </p>
  
  <p>(My experience with igraph is very limited). </p>
  
  <pre><code>      df2 = rbind(c(234,235,21.6,75),
        c(234,326,11.0,35),
        c(235,241,14.5,78),
        c(326,241,8.2,98),
        c(241,245,15.3,75),
        c(234,245,38.46,65))
  
        df2 = as.data.frame(df2)
        names(df2) = c("start_id","end_id","newcost","distance")
  
        require(igraph)
        g2 &lt;- graph.data.frame(df2, directed=FALSE)
        tmp2 = shortest.paths(g2,weights=E(g2)$newcost)
        tmp2 #this gives the matrix of newcost-weighted shortest distances
  </code></pre>
  
  <p>Where I could use help is how to find all paths, say using <code>optimal.path &lt;- get.shortest.paths</code>, and using <code>sum(E(g2, path = optimal.path)$distance)</code> to create the matrix of distances</p>
  
  <p>what I would really like is an edgelist of distances for all node pairs, like:</p>
  
  <pre><code>      startid endid shortestdist
        234     235     75
        234     245     208
  </code></pre>
  
  <p>What is tricky about this problem is that newcost is used to find the shortest paths, but what I want is the sum of another variable - the distance variable on each shortest path between node pairs.</p>