Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

select_edges_by_edge_id

Select edges in a graph using edge ID values


Description

Select edges in a graph object of class dgr_graph using edge ID values.

Usage

select_edges_by_edge_id(graph, edges, set_op = "union")

Arguments

graph

A graph object of class dgr_graph.

edges

A vector of edge IDs for the selection of edges present in the graph.

set_op

The set operation to perform upon consecutive selections of graph edges This can either be as a union (the default), as an intersection of selections with intersect, or, as a difference on the previous selection, if it exists.

Value

A graph object of class dgr_graph.

Examples

# Create a graph with 5 nodes
graph <-
  create_graph() %>%
  add_path(n = 5)

# Create a graph selection by selecting
# edges with edge IDs `1` and `2`
graph <-
  graph %>%
  select_edges_by_edge_id(
    edges = 1:2)

# Get the selection of edges
graph %>% get_selection()

# Perform another selection of edges,
# with edge IDs `1`, `2`, and `4`
graph <-
  graph %>%
  clear_selection() %>%
  select_edges_by_edge_id(
    edges = c(1, 2, 4))

# Get the selection of edges
graph %>% get_selection()

# Get the fraction of edges selected
# over all the edges in the graph
graph %>%
  {
    l <- get_selection(.) %>%
      length(.)
    e <- count_edges(.)
    l/e
  }

DiagrammeR

Graph/Network Visualization

v1.0.6.1
MIT + file LICENSE
Authors
Richard Iannone [aut, cre] (<https://orcid.org/0000-0003-3925-190X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.