Learn R Programming

smallstuff (version 1.0.3)

get_subgraphs: Split a Graph into Subgraphs

Description

Split a graph into subgraphs using the values in a vector to indicate which vertices belong together.

Usage

get_subgraphs(g, split)

Value

A list of graphs, where each graph is a subgraph of g

containing the vertices with the same value in split.

Arguments

g

the graph (an igraph object)

split

a vector with a value for each vertex in g

Examples

Run this code
g=igraph::graph_from_literal(1-2,2-3:4,3-4:5:6,5-1)
split=c("A","A","B","B","A","B")
igraph::V(g);split
igraph::V(get_subgraphs(g,split)[[1]])
igraph::V(get_subgraphs(g,split)[[2]])

Run the code above in your browser using DataLab