Learn R Programming

DiagrammeR (version 0.8.4)

get_non_nbrs: Get non-neighbors of a node in a graph

Description

Get the set of all nodes not neighboring a single graph node.

Usage

get_non_nbrs(graph, node)

Arguments

graph
a graph object of class dgr_graph that is created using create_graph.
node
a single-length vector containing a node ID value.

Value

a vector of node ID values.

Examples

Run this code
library(magrittr)

# Create a random, directed graph with 18 nodes
# and 22 edges
random_graph <-
  create_random_graph(
    n = 18,
    m = 22,
    directed = TRUE,
    fully_connected = TRUE,
    set_seed = 20) %>%
  set_global_graph_attrs(
    'graph', 'layout', 'sfdp') %>%
  set_global_graph_attrs(
    'graph', 'overlap', 'false')

# Find all non-neighbors of node `5`
random_graph %>%
  get_non_nbrs(5)
#>  [1] "3"  "4"  "6"  "7"  "8"  "9"  "10" "11" "13"
#> [12] "14" "15" "16" "17"

Run the code above in your browser using DataLab