你如何使用R中的igraph重新连接加权网络?

时间:2014-01-17 07:00:02

标签: r igraph

我曾尝试在R中使用igraph中的'重新连接',但它仅适用于未加权的网络。任何帮助???

2 个答案:

答案 0 :(得分:2)

我的igraph版本很乐意重新连接加权图表:

g <- graph.ring(10)
E(g)$weight <- seq_len(ecount(g))
E(g)$weight
# [1]  1  2  3  4  5  6  7  8  9 10
is.weighted(g)
# [1] TRUE
g2 <- rewire(g,niter=3)
plot(g2)
is.weighted(g2)
# [1] TRUE

版本是:

packageDescription("igraph")$Version
# [1] "0.6.6"

答案 1 :(得分:1)

使用igraph的1.0.1版本,请尝试以下操作:

# SAME EXAMPLE AS IN PREVIOUS ANSWER AND COMMENTS 
g <- graph.ring(10)
E(g)$weight <- seq_len(ecount(g))
E(g)$weight
# [1]  1  2  3  4  5  6  7  8  9 10
is.weighted(g)
# [1] TRUE
g2 <- rewire(g, with=each_edge(0.5)) #rewire vertices with constant probability
E(g2)$weight <- sample(E(g)$weight) #shuffle initial weights and assign them randomly to edges
plot(g2)
is.weighted(g2)
# [1] TRUE
E(g2)$weight
# [1]  3  6  2  4 10  1  9  8  7  5

请注意,此方法可能会导致多边缘或循环。