Skip to contents

Given an igraph object and an edge attribute, this function finds all unique values of the edge attribute in the graph and returns a list of igraph objects on the same vertex set where each element of the list has a graph containing only those edges with specified attributed.

Usage

split_igraph(g, e_attr, strip_vertex_attr = FALSE)

Arguments

g

An igraph object

e_attr

the name of an edge attribute in g

strip_vertex_attr

Whether to remove all vertex attribute from the new graphs

Value

A named list of igraph objects with names corresponding to the values of the edge attributes.

Examples

g <- igraph::sample_gnm(20, 60)
igraph::E(g)$color <-
  sample(c("red", "green"), 60, replace = TRUE)
split_igraph(g, "color")
#> $green
#> IGRAPH 5ae46ae U--- 20 29 -- Erdos-Renyi (gnm) graph
#> + attr: name (g/c), type (g/c), loops (g/l), m (g/n), color (e/c)
#> + edges from 5ae46ae:
#>  [1]  2-- 5  4-- 5  4-- 6  4-- 7  3-- 9  5-- 9  8--10  4--11  9--12 11--12
#> [11]  1--13  2--13 12--13  9--14 13--14  3--15  5--15  9--15 11--15 13--15
#> [21]  1--16  6--16  8--16 10--16  2--17  4--18  5--18 15--18 19--20
#> 
#> $red
#> IGRAPH 25d618b U--- 20 31 -- Erdos-Renyi (gnm) graph
#> + attr: name (g/c), type (g/c), loops (g/l), m (g/n), color (e/c)
#> + edges from 25d618b:
#>  [1]  1-- 3  2-- 4  3-- 5  1-- 7  3-- 7  6-- 8  4-- 9  7-- 9  4--10  5--11
#> [11]  8--11  3--12  6--12  8--13  4--14 10--14  2--15  4--15  5--16 12--16
#> [21]  6--17 12--17  1--19  5--19  6--19  9--19 13--19 15--19 11--20 15--20
#> [31] 18--20
#>