I have a question about assigning edge values to a network in R
using the set.edge.value
command of the network
package. The assigned values in my large network are just not right, therefore I generated a small network to make the problem easier visible and reproducible. Here is the code to generate the network (including the values to be assigned).
a <- c(rep("a",3), "b", "c", rep("d",3), rep("f",2), "g")
b <- c("c", "e", "f", "a", "g", "a", "e", "f", "b", "e", "c")
c <- 1:11
d <- data.frame(a,b,c)
mat <- network(d[,c(1,2)], directed=T, attrname="val")
set.edge.value(mat, "val", c)
mat2 <- as.matrix.network(mat, attrname="val")
The network now looks as follows.
> mat2
a b c d e f g
a 0 0 4 0 7 3 0
b 2 0 0 0 0 0 0
c 0 0 0 0 0 0 1
d 4 0 0 0 10 6 0
e 0 0 0 0 0 0 0
f 0 2 0 0 1 0 0
g 0 0 10 0 0 0 0
However, these are clearly the wrong values, as can be seen below in the edgelist form (plus c, the values). So the edge ab
should have the value 1
, ae
the value 2
, etc.The network fills in the right edges, i.e. only those that do exist, but the values are wrong. It seems to me that it uses the values in the vector c
and tries to fill every edge starting with aa
, then ab
, etc. (i.e. it fills the network by row), but only filling the existing edges. When it runs out of values, it starts all over again using the recycling rule. Does anyone have an idea how to fill the edges with the appropriate values? I've been trying that for a while now but I can't seem to figure it out, and Google is not much help either (or I'm looking for the wrong thing). Any help would be appreciated! Thanks!
> d
a b c
1 a c 1
2 a e 2
3 a f 3
4 b a 4
5 c g 5
6 d a 6
7 d e 7
8 d f 8
9 f b 9
10 f e 10
11 g c 11