Skip to contents

Convert an Adjacency List to an Adjacency Matrix

Usage

convert.adjacency.list.to.adjacency.matrix(
  adj.list,
  weight.list = NULL,
  mode = "undirected",
  remove.self.loops = TRUE
)

Arguments

adj.list

Adjacency list.

weight.list

Optional edge-weight list aligned with adj.list.

mode

Either "undirected" or "directed".

remove.self.loops

Logical; if TRUE, remove diagonal entries.

Value

Numeric adjacency matrix.

Examples

graph <- list(c(2L, 3L), 1L, 1L)
weights <- list(c(1, 2), 1, 2)
convert.adjacency.list.to.adjacency.matrix(graph, weights)
#>      [,1] [,2] [,3]
#> [1,]    0    1    2
#> [2,]    1    0    0
#> [3,]    2    0    0