Reputation: 6409
I would like to know how to interpret the output of the get.edgelist()
command in igraph
in R.
for example I generate a random graph:
a=erdos.renyi.game(100,0.5, directed=TRUE)
a=get.edgelist(a)
This gives me two columns and I would think that the first one represents nodes and the second the corresponding connections.
But this doesn't seem to be the case because some numbers are only represented in the second column but not the first. How can this be?
Upvotes: 2
Views: 3540
Reputation: 118859
By creating a small example, probably it becomes obvious?
set.seed(45)
g <- erdos.renyi.game(10, 0.5, directed = TRUE)
> get.adjacency(g)
10 x 10 sparse Matrix of class "dgCMatrix"
[1,] . 1 . 1 . . 1 1 1 1
[2,] . . . 1 . 1 1 1 1 .
[3,] 1 1 . 1 . 1 . . 1 .
[4,] 1 1 . . . . 1 1 1 1
[5,] . 1 . . . . 1 . . 1
[6,] . 1 1 1 1 . 1 . . .
[7,] 1 . 1 . . 1 . . 1 .
[8,] . 1 1 1 . 1 . . 1 .
[9,] 1 . 1 1 . 1 . . . 1
[10,] 1 . 1 . 1 1 . . 1 .
edges <- as.data.frame(get.edgelist(g))
edges <- edges[order(edges$V1, edges$V2), ]
> head(edges, 11)
V1 V2
7 1 2
18 1 4
34 1 7
39 1 8
42 1 9
1 1 10
19 2 4
28 2 6
35 2 7
40 2 8
43 2 9
You can see from the adjacency matrix that there are edges from row 1
to 2,4,7,8,9,10
, which is also reflected in the output from get.edgelist
. It gives you exactly what's in the adjacency matrix.
> table(edges$V1)
# 1 2 3 4 5 6 7 8 9 10
# 6 5 5 6 3 5 4 5 5 5
Upvotes: 1