Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

edgeMatrix

Compute an Edge Matrix or weight vector for a Graph


Description

For our purposes an edge matrix is a matrix with two rows and as many columns as there are edges. The entries in the first row are the index of the node the edge is from, those in the second row indicate the node the edge is to.

If the graph is “undirected” then the duplicates option can be used to indicate whether reciprocal edges are wanted. The default is to leave them out. In this case the notions of from and to are not relevant.

Usage

edgeMatrix(object, duplicates=FALSE)
eWV(g, eM, sep = ifelse(edgemode(g) == "directed", "->",
                 "--"), useNNames=FALSE)
pathWeights(g, p, eM=NULL)

Arguments

object

An object that inherits from graph.

g

An object that inherits from graph.

duplicates

Whether or not duplicate edges should be produced for “undirected” graphs.

eM

An edge matrix

sep

a character string to concatenate node labels in the edge label

useNNames

a logical; if TRUE, node names are used in the edge label; if FALSE, node indices are used

p

a vector of node names constituting a path in graph g

Details

Implementations for graphNEL, clusterGraph and distGraph are available.

Value

edgeMatrix returns a matrix with two rows, from and to, and as many columns as there are edges. Entries indicate the index in the node vector that corresponds to the appropriate end of the edge.

eWV uses the edge matrix to create an annotated vector of edge weights.

pathWeights returns an annotated vector of edge weights for a specified path in a graph.

Note

A path through an undirected graph may have several representations as a named vector of edges. Thus in the example, when the weights for path b-a-i are requested, the result is the pair of weights for edges a–b and a–i, as these are the edge labels computed for graph g1.

Author(s)

R. Gentleman

See Also

Examples

set.seed(123)
  g1 <- randomGraph(letters[1:10], 1:4, p=.3)
  edgeMatrix(g1)
  g2 <- new("clusterGraph", clusters=list(a=c(1,2,3), b=c(4,5,6)))
  em2 <- edgeMatrix(g2)
  eWV(g1, edgeMatrix(g1))
  eWV(g1, edgeMatrix(g1), useNNames=TRUE)
  pathWeights(g1, c("b", "a", "i"))

graph

graph: A package to handle graph data structures

v1.68.0
Artistic-2.0
Authors
R. Gentleman, Elizabeth Whalen, W. Huber, S. Falcon
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.