Is there any way to display edge weights when viewing the graph object as an edge list?
I want to do something in the spirit of:
get.edgelist(graph, attr='weight')
so as to view the edge pairings with the weights listed alongside the nodes, but that seems not to be allowed. Only way I know how to view the weights is to view the network data as an adjacency matrix. Hoping that's not the only way.
The weight w(E) of an edge E in a multigraph G is the sum of the degrees of its end vertices; and if G is a pseudograph and E is a loop, then w(E) is defined as twice the degree of its unique end vertex. The weight w(G) of a pseudograph G is defined as min{w(E); EG}.
In igraph edge weights are represented via an edge attribute, called 'weight'. The is_weighted function only checks that such an attribute exists. (It does not even checks that it is a numeric edge attribute.) Edge weights are used for different purposes by the different functions.
Edge Weights. Both Directed and Undirected Edges may be WEIGHTED or UNWEIGHTED. A WEIGHTED EDGE is like a tollway; it costs a certain amount to travel along that edge in either direction. An UNWEIGHTED EDGE, on the other hand, is like a freeway.
The edge-weight represents the money borrowed by one from another.
Using the example in the help page for function get.edgelist
in pkg:igraph:
> 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"
Another option is to use get.data.frame()
from the igraph
package
# 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With