Sometimes it is useful to work with a standard representation of a graph, like an edge list.
as_edgelist(graph, names = TRUE)A ecount(graph) by 2 numeric matrix.
as_edgelist() returns the list of edges in a graph.
graph_from_adjacency_matrix(), read_graph()
Other conversion:
as.matrix.igraph(),
as_adj_list(),
as_adjacency_matrix(),
as_biadjacency_matrix(),
as_data_frame(),
as_directed(),
as_graphnel(),
as_long_data_frame(),
graph_from_adj_list(),
graph_from_graphnel()
g <- sample_gnp(10, 2 / 10)
as_edgelist(g)
#> [,1] [,2]
#> [1,] 1 2
#> [2,] 1 5
#> [3,] 3 6
#> [4,] 5 6
#> [5,] 4 7
#> [6,] 5 8
#> [7,] 7 8
#> [8,] 2 10
#> [9,] 3 10
V(g)$name <- LETTERS[seq_len(gorder(g))]
as_edgelist(g)
#> [,1] [,2]
#> [1,] "A" "B"
#> [2,] "A" "E"
#> [3,] "C" "F"
#> [4,] "E" "F"
#> [5,] "D" "G"
#> [6,] "E" "H"
#> [7,] "G" "H"
#> [8,] "B" "J"
#> [9,] "C" "J"