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
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)
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")))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(graph)
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
rbind, rownames, sapply, setdiff, sort, table, tapply, union,
unique, unsplit
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/graph/addNode.Rd_%03d_medium.png", width=480, height=480)
> ### Name: addNode
> ### Title: addNode
> ### Aliases: addNode addNode,character,graphNEL,missing-method
> ### addNode,character,graphNEL,list-method
> ### addNode,character,distGraph,list-method
> ### addNode,character,graphBAM,missing-method
> ### Keywords: manip
>
> ### ** Examples
>
>
> 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)
> 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")))
>
>
>
>
>
>
> dev.off()
null device
1
>