R igraph 手册页

如果您从 R 中使用 igraph,请使用此选项

as.matrix.igraph {igraph}R 文档

将 igraph 对象转换为邻接矩阵或边列表矩阵

描述

获取存储为 igraph 对象的网络的邻接矩阵或边列表表示。

用法

## S3 method for class 'igraph'
as.matrix(x, matrix.type = c("adjacency", "edgelist"), ...)

参数

x

igraph 类的对象,即网络

matrix.type

字符,要返回的矩阵类型,目前支持 "adjacency" 或 "edgelist"

...

传递给/来自其他方法的其他参数

详细信息

如果 matrix.type"edgelist",则返回一个两列数字边列表矩阵。attrname 的值将被忽略。

如果 matrix.type"adjacency",则返回一个方形邻接矩阵。对于邻接矩阵,您可以使用 attr 关键字参数来使用矩阵单元格中的边属性值。有关更多详细信息,请参见 as_adjacency_matrix 的文档。

通过 ... 传递的其他参数将根据 matrix.type 的值传递给 as_adjacency_matrixas_edgelist

根据 matrix.type 的值,返回一个方形邻接矩阵或一个表示边列表的两列数字矩阵。

作者

Michal Bojanowski,最初来自 intergraph

参见

as_adjacency_matrix, as_edgelist

示例


g <- make_graph("zachary")
as.matrix(g, "adjacency")
as.matrix(g, "edgelist")
# use edge attribute "weight" 
E(g)$weight <- rep(1:10, each=ecount(g))
as.matrix(g, "adjacency", sparse=FALSE, attr="weight")


[包 igraph 版本 1.3.5 索引]