conversion {igraph} | R Documentation |
Sometimes it is useful to have a standard representation of a graph, like an adjacency matrix or an edge list.
get.adjacency(graph, type=c("both", "upper", "lower"), attr=NULL, names=TRUE, binary=FALSE, sparse=FALSE) get.edgelist(graph, names=TRUE)
graph |
The graph to convert. |
type |
Gives how to create the adjacency matrix for undirected
graphs. It is ignored for directed graphs. Possible values:
|
attr |
Either |
names |
Logical constant. For for |
binary |
Logical, whether to return a binary matrix. This argument
is ignored if |
sparse |
Logical scalar, whether to create a sparse matrix. The
‘ |
get.adjacency
returns the adjacency matrix of a graph, a
regular R matrix if sparse
is FALSE
, or a sparse
matrix, as defined in the ‘Matrix
’ package, if
sparse
if TRUE
.
get.edgelist
returns the list of edges in a graph.
A vcount(graph)
by vcount(graph)
(usually) numeric
matrix for get.adjacency
. (This can be huge!) Note that a
non-numeric matrix might be returned if attr
is a non-numeric
edge attribute.
A ecount(graph)
by 2 numeric matrix for get.edgelist
.
Gabor Csardi csardi@rmki.kfki.hu
g <- erdos.renyi.game(10, 2/10) get.edgelist(g) get.adjacency(g) V(g)$name <- letters[1:vcount(g)] get.adjacency(g) E(g)$weight <- runif(ecount(g)) get.adjacency(g, attr="weight")