addNode: addNode

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

Description

Add one or more nodes to a graph.

Usage

1
addNode(node, object, edges)

Arguments

node

A character vector of node names.

object

A graph

edges

A named list of edges.

Details

The supplied nodes are added to the set of nodes of the object.

If edges are provided then their must be the same number as there are nodes and the must be in the same order. The elements of the edges list are vectors. They can be character vectors of node labels for nodes in object and if so then they are added with unit weights. If the vector is numeric then it must be named (with labels corresponding to nodes in the object) and the values are taken to be the edge weights.

When the object is a distGraph then the edges must be supplied and they must contain appropriate distances for all nodes both those in object and those supplied.

Value

A new graph of the same class as object with the supplied node added to the set of nodes.

Author(s)

R. Gentleman

See Also

removeNode, removeEdge, addEdge

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  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 <- new("graphNEL", nodes=V, edgeL=edL1)
  gX <- addNode("X", gR)

set.seed(123)
g1 <- randomGraph(letters[1:10], 1:4, p=.3)
g2 <- addNode("z", g1, edges=list(c("a", "h", "g")))

vgpprasad91/graph documentation built on May 20, 2019, 2:46 p.m.