R/Igraph如何在边列表中显示边权重?

7

在查看边列表的图形对象时,有没有显示边权重的方法?

我想做类似这样的事情:

get.edgelist(graph, attr='weight')

为了查看边权值与节点列表一起列出的边对,但似乎不允许这样做。我知道的查看权值的唯一方法是将网络数据视为邻接矩阵。希望这不是唯一的方法。
2个回答

16

使用pkg:igraph中函数get.edgelist在帮助页面中的示例:

> cbind( get.edgelist(g) , round( E(g)$weight, 3 ))
      [,1] [,2] [,3]   
 [1,] "a"  "b"  "0.342"
 [2,] "b"  "d"  "0.181"
 [3,] "b"  "e"  "0.403"
 [4,] "b"  "f"  "0.841"
 [5,] "d"  "f"  "0.997"
 [6,] "e"  "g"  "0.029"
 [7,] "a"  "h"  "0.17" 
 [8,] "b"  "j"  "0.69" 
 [9,] "g"  "j"  "0.422"

4
另一个选项是使用igraph软件包中的get.data.frame()
# create a random graph with weighted edges      
g <- erdos.renyi.game(5, 5/10, directed = TRUE)
E(g)$weight <- runif(length(E(g)), 1, 5)

# pull nodes and edge weights
get.data.frame(g)

   from to   weight
1     1  5 4.716679
2     2  1 4.119414
3     1  2 4.535791
4     2  5 2.486553
5     3  2 4.932118
6     5  2 3.353693
7     1  3 3.003062
8     2  3 3.350118
9     1  4 2.929069
10    2  4 4.929474
11    5  4 4.333134

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接