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    3
#>  [2,]    4    6
#>  [3,]    4    7
#>  [4,]    2    8
#>  [5,]    5    8
#>  [6,]    4    9
#>  [7,]    6    9
#>  [8,]    2   10
#>  [9,]    9   10

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