Skip to contents

Delete edges from a graph

Usage

delete_edges(graph, edges)

Arguments

graph

The input graph.

edges

The edges to remove, specified as an edge sequence. Typically this is either a numeric vector containing edge IDs, or a character vector containing the IDs or names of the source and target vertices, separated by |

Value

The graph, with the edges removed.

delete_edges(), get_eids(), edges(), ecount(), vcount()

Examples

g <- make_ring(10) %>%
  delete_edges(seq(1, 9, by = 2))
g
#> ── <igraph> Ring graph ────────────────────────────────────────────── 36e73df ──
#>  undirected
#>  10 vertices · 5 edges
#> 
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph:  name <chr>, mutual <lgl>, circular <lgl>
#> 
#> ── Edges ───────────────────────────────────────────────────────────────────────
#> [1] 2 ─ 3   4 ─ 5   6 ─ 7   8 ─ 9   1 ─ 10 

g <- make_ring(10) %>%
  delete_edges("10|1")
g
#> ── <igraph> Ring graph ────────────────────────────────────────────── ffcf22f ──
#>  undirected
#>  10 vertices · 9 edges
#> 
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph:  name <chr>, mutual <lgl>, circular <lgl>
#> 
#> ── Edges ───────────────────────────────────────────────────────────────────────
#> [1] 1 ─ 2   2 ─ 3   3 ─ 4   4 ─ 5   5 ─ 6   6 ─ 7   7 ─ 8   8 ─ 9   9 ─ 10 

g <- make_ring(5)
g <- delete_edges(g, get_edge_ids(g, c(1, 5, 4, 5)))
g
#> ── <igraph> Ring graph ────────────────────────────────────────────── 60d5563 ──
#>  undirected
#>  5 vertices · 3 edges
#> 
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph:  name <chr>, mutual <lgl>, circular <lgl>
#> 
#> ── Edges ───────────────────────────────────────────────────────────────────────
#> [1] 1 ─ 2  2 ─ 3  3 ─ 4