如果您从 R 中使用 igraph,请使用此选项
as.matrix.igraph {igraph} | R 文档 |
获取存储为 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_matrix
或 as_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")