| Matrics to Graph coersions {graph} | R Documentation |
A collection of functions and methods to convert various forms of matrices into graph objects.
aM2bpG(aM) ftM2adjM(ft, W=NULL, V=NULL, edgemode="directed")
ft |
A matrix with two columns containing the from/to representation of graph edges. |
W |
An optional vector of edge weights. |
V |
An optional vector of node names. |
aM |
An affiliation matrix for a bipartite graph. |
edgemode |
Specifies if the resulting graph is to be directed or undirected |
In the fuction ftM2adjM, a from/to matrix is converted
into an adjacency matrix (which can then be coerced directly into
a graphNEL-class with as. Ths first column of the
ft represents the from nodes and the second column
represents to nodes. This representation does not allow for
unconnected nodes except with the V argument (see below). The
edgemode parameter can be used to specify if the desired output
is a directed or undirected graph.
Also in ftM2adjM, W is an optional vector of edge weights.
The order of the edge weights in the vector should correspond to the
order of the edges recorded in L. If it is not specified, edge
weights of 1 are assigned by default. The V argument is an
optional vector of node names. All nodes in ft must be contained
in V, but not all nodes in V must be contained in
ft. If V is not specified, it is set to all nodes
represented in ft or M. Specifying V is most useful
for creating a graph that includes nodes with degree 0.
aM is an affiliation matrix as frequently used in social networks
analysis. The rows of aM represent actors, and the columns
represent events. An entry of "1" in the ith row and jth column
represents affiliation of the ith actor with the jth event. Weighted
entries may also be used. aM2bpG returns a graphNEL object with
nodes consisting of the set of actors and events, and directed (possibly
weighted) edges from the actors to their corresponding events. If
plotted using Rgraphviz and the dot layout, the bipartite structure of
the graph returned by aM2bpG should be evident.
An adjacency matrix can be directly coerced into a
graphNEL using the as method. If the matrix is a
symmetric matrix, then the resulting graph will be undirected,
otherwise it will be directed.
For aM2bpG, an object of class graphNEL. For
ftM2adjM, an adjacency matrix representation of the coerced graph.
Denise Scholtens
From <- c("A","A","C","C")
To <- c("B","C","A","D")
L <- cbind(From,To)
W <- 1:4
M1 <- ftM2adjM(L,W, edgemode="undirected")
M2 <- ftM2adjM(L)
G1 <- as(M1, "graphNEL")
G2 <- as(M2, "graphNEL")