Description Usage Arguments Details Value Author(s) See Also Examples
A function to combine, or collapse, a specified set of nodes in a graph.
1 2 3 | combineNodes(nodes, graph, newName, ...)
## S4 method for signature 'character,graphNEL,character'
combineNodes(nodes, graph, newName, collapseFunction=sum)
|
nodes |
A set of nodes that are to be collapsed. |
graph |
The graph containing the nodes |
newName |
The name for the new, collapsed node. |
collapseFunction |
Function or character giving the name of a function used to collapse the edge weights after combining nodes. The default is to sum up the weights, but mean would be a useful alternative. |
... |
Additional arguments for the generic |
The nodes specified are reduced to a single new node with label given
by newName
. The in and out edges of the set of nodes are all
made into in and out edges for the new node.
An new instance of a graph of the same class as graph
is
returned. This new graph has the specified nodes reduced to a single
node.
R. Gentleman
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | V <- LETTERS[1:4]
edL1 <- vector("list", length=4)
names(edL1) <- V
for(i in 1:4)
edL1[[i]] <- list(edges=c(2,1,4,3)[i], weights=sqrt(i))
gR <- graphNEL(nodes=V, edgeL=edL1, edgemode="directed")
gR <- addNode("M", gR)
gR <- addEdge("M", "A", gR, 1)
gR <- addEdge("B", "D", gR, 1)
gX <- combineNodes(c("B","D"), gR, "X")
gR <- addNode("K", gR)
gR <- addEdge(c("K","K"), c("D", "B"), gR, c(5,3))
edgeWeights(combineNodes(c("B","D"), gR, "X"))$K
edgeWeights(combineNodes(c("B","D"), gR, "X", mean))$K
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.