Learn R Programming

igraph (version 1.3.5)

as.matrix.igraph: Convert igraph objects to adjacency or edge list matrices

Description

Get adjacency or edgelist representation of the network stored as an igraph object.

Usage

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

Value

Depending on the value of matrix.type either a square adjacency matrix or a two-column numeric matrix representing the edgelist.

Arguments

x

object of class igraph, the network

matrix.type

character, type of matrix to return, currently "adjacency" or "edgelist" are supported

...

other arguments to/from other methods

Author

Michal Bojanowski, originally from the intergraph package

Details

If matrix.type is "edgelist", then a two-column numeric edge list matrix is returned. The value of attrname is ignored.

If matrix.type is "adjacency", then a square adjacency matrix is returned. For adjacency matrices, you can use the attr keyword argument to use the values of an edge attribute in the matrix cells. See the documentation of as_adjacency_matrix for more details.

Other arguments passed through ... are passed to either as_adjacency_matrix or as_edgelist depending on the value of matrix.type.

See Also

as_adjacency_matrix, as_edgelist

Examples

Run this code

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")

Run the code above in your browser using DataLab