跳到内容

从图中创建邻接列表,可用于相邻边或相邻顶点

用法

as_adj_list(
  graph,
  mode = c("all", "out", "in", "total"),
  loops = c("twice", "once", "ignore"),
  multiple = TRUE
)

as_adj_edge_list(
  graph,
  mode = c("all", "out", "in", "total"),
  loops = c("twice", "once", "ignore")
)

参数

graph

输入图。

mode

字符标量,它给出了要在列表中包含的相邻边/顶点的类型。‘out’ 表示输出边/顶点,‘in’ 表示输入边/顶点,‘all’ 表示两者。对于无向图,此参数将被忽略。

loops

字符标量,选项包括 "ignore" (忽略环路), "twice" (包含环路边两次) 和 "once" (包含环路边一次)。"twice" 不允许用于有向图,将替换为 "once"

multiple

逻辑标量,设置为 FALSE 以仅使用每组平行边中的一个代表。

igraph.vs 列表或数值向量列表,具体取决于 igraph_opt("return.vs.es") 的值,有关性能特征,请参阅详细信息。

详细信息

as_adj_list() 返回一个数值向量列表,其中包含所有顶点的相邻顶点(根据 mode 参数)的 ID。

as_adj_edge_list() 返回一个数值向量列表,其中包含所有顶点的相邻边(根据 mode 参数)的 ID。

如果 igraph_opt("return.vs.es") 为 true(默认值),则邻接列表的数值向量将被强制转换为 igraph.vs,这对于大型图来说可能是一个非常耗时的操作。

作者

Gabor Csardi csardi.gabor@gmail.com

示例


g <- make_ring(10)
as_adj_list(g)
#> [[1]]
#> + 2/10 vertices, from 6a8e646:
#> [1]  2 10
#> 
#> [[2]]
#> + 2/10 vertices, from 6a8e646:
#> [1] 1 3
#> 
#> [[3]]
#> + 2/10 vertices, from 6a8e646:
#> [1] 2 4
#> 
#> [[4]]
#> + 2/10 vertices, from 6a8e646:
#> [1] 3 5
#> 
#> [[5]]
#> + 2/10 vertices, from 6a8e646:
#> [1] 4 6
#> 
#> [[6]]
#> + 2/10 vertices, from 6a8e646:
#> [1] 5 7
#> 
#> [[7]]
#> + 2/10 vertices, from 6a8e646:
#> [1] 6 8
#> 
#> [[8]]
#> + 2/10 vertices, from 6a8e646:
#> [1] 7 9
#> 
#> [[9]]
#> + 2/10 vertices, from 6a8e646:
#> [1]  8 10
#> 
#> [[10]]
#> + 2/10 vertices, from 6a8e646:
#> [1] 1 9
#> 
as_adj_edge_list(g)
#> [[1]]
#> + 2/10 edges from 6a8e646:
#> [1] 1-- 2 1--10
#> 
#> [[2]]
#> + 2/10 edges from 6a8e646:
#> [1] 1--2 2--3
#> 
#> [[3]]
#> + 2/10 edges from 6a8e646:
#> [1] 2--3 3--4
#> 
#> [[4]]
#> + 2/10 edges from 6a8e646:
#> [1] 3--4 4--5
#> 
#> [[5]]
#> + 2/10 edges from 6a8e646:
#> [1] 4--5 5--6
#> 
#> [[6]]
#> + 2/10 edges from 6a8e646:
#> [1] 5--6 6--7
#> 
#> [[7]]
#> + 2/10 edges from 6a8e646:
#> [1] 6--7 7--8
#> 
#> [[8]]
#> + 2/10 edges from 6a8e646:
#> [1] 7--8 8--9
#> 
#> [[9]]
#> + 2/10 edges from 6a8e646:
#> [1] 8-- 9 9--10
#> 
#> [[10]]
#> + 2/10 edges from 6a8e646:
#> [1] 1--10 9--10
#>