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

Description Usage Arguments Details Value See Also Examples

Description

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

Usage

1
2
3
  as.matrix.igraph(x,
    matrix.type = c("adjacency", "edgelist"),
    attrname = NULL, sparse = FALSE, ...)

Arguments

x

object of class igraph, the network

matrix.type

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

attrname

character, name of the edge attribute to use to fill in the cells of the adjacency matrix

sparse

logical, whether to return a sparse matrix

...

other arguments to/from other methods

Details

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

If matrix.type is "adjacency" then a square adjacency matrix is returned. If attrname is NULL (default) the matrix is binary. Otherwise attrname can be a name of edge attribute of x. In that case the cells of the results are the values of that attribute.

Other arguments passed through ... are passed to either get.adjacency or get.edgelist depending on the value of matrix.type.

Value

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

See Also

get.adjacency, get.edgelist

Examples

1
2
3
4
5
data(exIgraph)
as.matrix(exIgraph, "adjacency")
as.matrix(exIgraph, "edgelist")
# use edge attribute "label"
as.matrix(exIgraph, "adjacency", sparse=FALSE, attr="label")

Example output

      [,1]      
 [1,] 15        
 [2,] TRUE      
 [3,] Numeric,11
 [4,] Numeric,11
 [5,] Numeric,11
 [6,] Numeric,11
 [7,] Numeric,16
 [8,] Numeric,16
 [9,] List,4    
[10,] ?         
attr(,"class")
[1] "igraph"
      [,1]      
 [1,] 15        
 [2,] TRUE      
 [3,] Numeric,11
 [4,] Numeric,11
 [5,] Numeric,11
 [6,] Numeric,11
 [7,] Numeric,16
 [8,] Numeric,16
 [9,] List,4    
[10,] ?         
attr(,"class")
[1] "igraph"
      [,1]      
 [1,] 15        
 [2,] TRUE      
 [3,] Numeric,11
 [4,] Numeric,11
 [5,] Numeric,11
 [6,] Numeric,11
 [7,] Numeric,16
 [8,] Numeric,16
 [9,] List,4    
[10,] ?         
attr(,"class")
[1] "igraph"

intergraph documentation built on May 2, 2019, 4:55 p.m.