get.inducedSubgraph {network} | R Documentation |
Given a set of vertex IDs, get.inducedSubgraph
returns the subgraph induced by the specified vertices (i.e., the vertices and all associated edges). Optionally, passing a second set of alters returns the cut from the first to the second set (i.e., all edges passing between the sets), along with the associated endpoints. In both cases, the result is returned as a network object, with all attributes of the selected edges and/or vertices (and any network attributes) preserved.
get.inducedSubgraph(x, v, alters = NULL) x %s% v
x |
an object of class |
v |
a vector of vertex IDs, or, for |
alters |
optionally, a second vector of vertex IDs. Must be disjoint with |
For get.inducedSubgraph
, v
must be a vector of vertex IDs. If alter=NULL
, the subgraph induced by these vertices is returned. Calling %s%
with a single vector of vertices has an identical effect.
Where alters
is specified, it must be a vector of IDs disjoint with v
. Where both are given, the edges spanning v
and alters
are returned, along with the vertices in question. (Technically, only the edges really constitute the “cut,” but the vertices are included as well.) The same result can be obtained with the %s%
operator by passing a two-element list on the right hand side; the first element is then interpreted as v
, and the second as alters
.
Any network, vertex, or edge attributes for the selected network elements are retained (although features such as vertex IDs and the network size will typically change). These are copies of the elements in the original network, which is not altered by this function.
A network
object containing the induced subgraph.
Carter T. Butts buttsc@uci.edu
#Load the Drabek et al. EMON data data(emon) #For the Mt. St. Helens, EMON, several types of organizations are present: type<-emon$MtStHelens %v% "Sponsorship" #Plot interactions among the state organizations plot(emon$MtStHelens %s% which(type=="State"), displaylabels=TRUE) #Plot state/federal interactions plot(emon$MtStHelens %s% list(which(type=="State"), which(type=="Federal")), displaylabels=TRUE) #Plot state interactions with everyone else plot(emon$MtStHelens %s% list(which(type=="State"), which(type!="State")), displaylabels=TRUE)