Create adjacency lists from a graph, either for adjacent edges or for neighboring vertices
Arguments
- graph
The input graph.
- mode
Character scalar, it gives what kind of adjacent edges/vertices to include in the lists. ‘
out
’ is for outgoing edges/vertices, ‘in
’ is for incoming edges/vertices, ‘all
’ is for both. This argument is ignored for undirected graphs.- loops
Character scalar, one of
"ignore"
(to omit loops),"twice"
(to include loop edges twice) and"once"
(to include them once)."twice"
is not allowed for directed graphs and will be replaced with"once"
.- multiple
Logical scalar, set to
FALSE
to use only one representative of each set of parallel edges.
Value
A list of igraph.vs
or a list of numeric vectors depending on
the value of igraph_opt("return.vs.es")
, see details for performance
characteristics.
Details
as_adj_list()
returns a list of numeric vectors, which include the ids
of neighbor vertices (according to the mode
argument) of all
vertices.
as_adj_edge_list()
returns a list of numeric vectors, which include the
ids of adjacent edges (according to the mode
argument) of all
vertices.
If igraph_opt("return.vs.es")
is true (default), the numeric
vectors of the adjacency lists are coerced to igraph.vs
, this can be
a very expensive operation on large graphs.
See also
as_edgelist()
, as_adjacency_matrix()
Other conversion:
as.matrix.igraph()
,
as_adjacency_matrix()
,
as_biadjacency_matrix()
,
as_data_frame()
,
as_directed()
,
as_edgelist()
,
as_graphnel()
,
as_long_data_frame()
,
graph_from_adj_list()
,
graph_from_graphnel()
Author
Gabor Csardi csardi.gabor@gmail.com
Examples
g <- make_ring(10)
as_adj_list(g)
#> [[1]]
#> + 2/10 vertices, from 5eec891:
#> [1] 2 10
#>
#> [[2]]
#> + 2/10 vertices, from 5eec891:
#> [1] 1 3
#>
#> [[3]]
#> + 2/10 vertices, from 5eec891:
#> [1] 2 4
#>
#> [[4]]
#> + 2/10 vertices, from 5eec891:
#> [1] 3 5
#>
#> [[5]]
#> + 2/10 vertices, from 5eec891:
#> [1] 4 6
#>
#> [[6]]
#> + 2/10 vertices, from 5eec891:
#> [1] 5 7
#>
#> [[7]]
#> + 2/10 vertices, from 5eec891:
#> [1] 6 8
#>
#> [[8]]
#> + 2/10 vertices, from 5eec891:
#> [1] 7 9
#>
#> [[9]]
#> + 2/10 vertices, from 5eec891:
#> [1] 8 10
#>
#> [[10]]
#> + 2/10 vertices, from 5eec891:
#> [1] 1 9
#>
as_adj_edge_list(g)
#> [[1]]
#> + 2/10 edges from 5eec891:
#> [1] 1-- 2 1--10
#>
#> [[2]]
#> + 2/10 edges from 5eec891:
#> [1] 1--2 2--3
#>
#> [[3]]
#> + 2/10 edges from 5eec891:
#> [1] 2--3 3--4
#>
#> [[4]]
#> + 2/10 edges from 5eec891:
#> [1] 3--4 4--5
#>
#> [[5]]
#> + 2/10 edges from 5eec891:
#> [1] 4--5 5--6
#>
#> [[6]]
#> + 2/10 edges from 5eec891:
#> [1] 5--6 6--7
#>
#> [[7]]
#> + 2/10 edges from 5eec891:
#> [1] 6--7 7--8
#>
#> [[8]]
#> + 2/10 edges from 5eec891:
#> [1] 7--8 8--9
#>
#> [[9]]
#> + 2/10 edges from 5eec891:
#> [1] 8-- 9 9--10
#>
#> [[10]]
#> + 2/10 edges from 5eec891:
#> [1] 1--10 9--10
#>