Skip to contents

Sometimes it is useful to work with a standard representation of a graph, like an edge list.

Usage

as_edgelist(graph, names = TRUE)

Arguments

graph

The graph to convert.

names

Whether to return a character matrix containing vertex names (i.e. the name vertex attribute) if they exist or numeric vertex ids.

Value

A ecount(graph) by 2 numeric matrix.

Details

as_edgelist() returns the list of edges in a graph.

Examples


g <- sample_gnp(10, 2 / 10)
as_edgelist(g)
#>      [,1] [,2]
#> [1,]    1    6
#> [2,]    3    7
#> [3,]    3    8
#> [4,]    1    9
#> [5,]    8    9
#> [6,]    3   10
#> [7,]    6   10
#> [8,]    8   10

V(g)$name <- LETTERS[seq_len(gorder(g))]
as_edgelist(g)
#>      [,1] [,2]
#> [1,] "A"  "F" 
#> [2,] "C"  "G" 
#> [3,] "C"  "H" 
#> [4,] "A"  "I" 
#> [5,] "H"  "I" 
#> [6,] "C"  "J" 
#> [7,] "F"  "J" 
#> [8,] "H"  "J"