add.vertices: Add Vertices to an Existing Network

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

Description

add.vertices adds a specified number of vertices to an existing network; if desired, attributes for the new vertices may be specified as well.

Usage

1
add.vertices(x, nv, vattr = NULL, last.mode = TRUE, ...)

Arguments

x

an object of class network

nv

the number of vertices to add

vattr

optionally, a list of attributes with one entry per new vertex

last.mode

logical; should the new vertices be added to the last (rather than the first) mode of a bipartite network?

...

possible additional arguments to add.vertices

Details

New vertices are generally appended to the end of the network (i.e., their vertex IDs begin with network.size(x) an count upward). The one exception to this rule is when x is bipartite and last.mode==FALSE. In this case, new vertices are added to the end of the first mode, with existing second-mode vertices being permuted upward in ID. (x's bipartite attribute is adjusted accordingly.)

Note that the attribute format used here is based on the internal (vertex-wise) storage method, as opposed to the attribute-wise format used by network. Specifically, vattr should be a list with one entry per new vertex, the ith element of which should be a list with an element for every attribute of the ith vertex. (If the required na attribute is not given, it will be automatically created.)

Value

Invisibly, a pointer to the updated network object; add.vertices modifies its argument in place.

Note

add.vertices was converted to an S3 generic funtion in version 1.9, so it actually calls add.vertices.network by default and may call other versions depending on context (i.e. when called with a networkDynamic object).

Author(s)

Carter T. Butts buttsc@uci.edu

References

Butts, C. T. (2008). “network: a Package for Managing Relational Data in R.” Journal of Statistical Software, 24(2). http://www.jstatsoft.org/v24/i02/

See Also

network, get.vertex.attribute, set.vertex.attribute

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#Initialize a network object
g<-network.initialize(5)
g

#Add five more vertices
add.vertices(g,5)
g

#Create two more, with attributes
vat<-replicate(2,list(is.added=TRUE,num.added=2),simplify=FALSE)
add.vertices(g,2,vattr=vat)
g%v%"is.added"       #Values are only present for the new cases
g%v%"num.added"

#Add to a bipartite network
bip <-network.initialize(5,bipartite=3)
get.network.attribute(bip,'bipartite') # how many vertices in first mode?
add.vertices(bip,3,last.mode=FALSE)
get.network.attribute(bip,'bipartite')

Example output

network: Classes for Relational Data
Version 1.13.0 created on 2015-08-31.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
                    Mark S. Handcock, University of California -- Los Angeles
                    David R. Hunter, Penn State University
                    Martina Morris, University of Washington
                    Skye Bender-deMoll, University of Washington
 For citation information, type citation("network").
 Type help("network-package") to get started.

 Network attributes:
  vertices = 5 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  total edges= 0 
    missing edges= 0 
    non-missing edges= 0 

 Vertex attribute names: 
    vertex.names 

No edge attributes
 Network attributes:
  vertices = 10 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  total edges= 0 
    missing edges= 0 
    non-missing edges= 0 

 Vertex attribute names: 
    vertex.names 

No edge attributes
 [1]   NA   NA   NA   NA   NA   NA   NA   NA   NA   NA TRUE TRUE
 [1] NA NA NA NA NA NA NA NA NA NA  2  2
[1] 3
[1] 6

network documentation built on May 2, 2019, 5:16 p.m.