# graph_from_adj_list: Create graphs from adjacency lists In igraph: Network Analysis and Visualization

## Create graphs from adjacency lists

### Description

An adjacency list is a list of numeric vectors, containing the neighbor vertices for each vertex. This function creates an igraph graph object from such a list.

### Usage

``````graph_from_adj_list(
mode = c("out", "in", "all", "total"),
duplicate = TRUE
)
``````

### Arguments

 `adjlist` The adjacency list. It should be consistent, i.e. the maximum throughout all vectors in the list must be less than the number of vectors (=the number of vertices in the graph). `mode` Character scalar, it specifies whether the graph to create is undirected (‘all’ or ‘total’) or directed; and in the latter case, whether it contains the outgoing (‘out’) or the incoming (‘in’) neighbors of the vertices. `duplicate` Logical scalar. For undirected graphs it gives whether edges are included in the list twice. E.g. if it is `TRUE` then for an undirected `{A,B}` edge `graph_from_adj_list()` expects `A` included in the neighbors of `B` and `B` to be included in the neighbors of `A`. This argument is ignored if `mode` is `out` or `⁠in⁠`.

### Details

Adjacency lists are handy if you intend to do many (small) modifications to a graph. In this case adjacency lists are more efficient than igraph graphs.

The idea is that you convert your graph to an adjacency list by `as_adj_list()`, do your modifications to the graphs and finally create again an igraph graph by calling `graph_from_adj_list()`.

### Value

An igraph graph object.

### Author(s)

Gabor Csardi csardi.gabor@gmail.com

`as_edgelist()`

Other conversion: `as.directed()`, `as.matrix.igraph()`, `as_adj_list()`, `as_adjacency_matrix()`, `as_data_frame()`, `as_edgelist()`, `as_graphnel()`, `as_incidence_matrix()`, `as_long_data_frame()`, `graph_from_graphnel()`

### Examples

``````
## Directed
g <- make_ring(10, directed = TRUE)
al <- as_adj_list(g, mode = "out")
graph.isomorphic(g, g2)

## Undirected
g <- make_ring(10)
g2 <- graph_from_adj_list(al, mode = "all")
graph.isomorphic(g, g2)
ecount(g2)
g3 <- graph_from_adj_list(al, mode = "all", duplicate = FALSE)
ecount(g3)
which_multiple(g3)
``````

igraph documentation built on Aug. 10, 2023, 9:08 a.m.