Learn R Programming

network (version 1.0-1)

deletion.methods: Remove Elements from a Network Object

Description

delete.edges removes one or more edges (specified by their internal ID numbers) from a network; delete.vertices performs the same task for vertices (removing all associated edges in the process).

Usage

delete.edges(x, eid)
delete.vertices(x, vid)

Arguments

x
an object of class network.
eid
a vector of edge IDs.
vid
a vector of vertex IDs.

Value

  • Invisibly, a pointer to the updated network; these functions modify their arguments in place.

Details

Note that an edge's ID number corresponds to its order within x$mel. To determine edge IDs, see get.edgeIDs. Likewise, vertex ID numbers reflect the order with which vertices are listed internally (e.g., the order of x$oel and x$iel, or that used by as.matrix.network.adjacency). When vertices are removed from a network, all edges having those vertices as endpoints are removed as well. Edges can also be added/removed via the extraction/replacement operators. See the associated man page for details.

References

Butts, C.T. 2002. ``Memory Structures for Relational Data in R: Classes and Interfaces'' Working Paper.

See Also

get.edgeIDs, network.extraction

Examples

Run this code
#Create a network with three edges
m<-matrix(0,3,3)
m[1,2]<-1; m[2,3]<-1; m[3,1]<-1
g<-network(m)

as.matrix.network(g)
delete.edges(g,2)              #Remove an edge
as.matrix.network(g)
delete.vertices(g,2)           #Remove a vertex
as.matrix.network(g)

#Can also remove edges using extraction/replacement operators
g<-network(m)
g[1,2]<-0                      #Remove an edge
g[,]
g[,]<-0                        #Remove all edges
g[,]

Run the code above in your browser using DataLab