A previous answer to another question provided some code to rewire a weighted graph as:
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
Playing with this code however shows that NAs are introduced in to the edge weights vector:
set.seed(1)
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)
E(g2)$weight
# [1] 1 2 4 5 6 7 9 NA NA NA
is.weighted(g2)
# [1] TRUE
Following from this I have two related questions:
1) Is the easiest way to fix the NA problem to just reallocate edges manually as in:
g2 <- rewire(g,niter=3)
E(g2)$weight <- sample( seq_len(ecount(g)) )
or is there a better way in which we can correct this in igraph
or at least explain what is going on in igraph
for this to happen?
2) Is there a rewiring system that also randomises the the weights so that that the network retains its total strength but both the binary edges are rewired and the individual edge weights across edges change swell?
e.g. not just
id id w
A - B 6
C - D 1
E - F 1
to
id id w
A - C 6
D - E 1
B - F 1
but also does:
id id w
A - B 6
C - D 1
E - F 1
to
id id w
A - C 4
D - E 3
B - F 1