edgeMatrix: Compute an Edge Matrix or weight vector for a Graph

Description Usage Arguments Details Value Note Author(s) See Also Examples

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

1
2
3
4
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

edges

Examples

1
2
3
4
5
6
7
8
  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"))

vjcitn/graph documentation built on Dec. 23, 2021, 4:06 p.m.