Get all common neighbors between two or more nodes

Description

With two or more nodes, get the set of common neighboring nodes.

Usage

1
get_common_nbrs(graph, nodes)

Arguments

graph

a graph object of class dgr_graph that is created using create_graph.

nodes

a vector of node ID values of length at least 2.

Value

a vector of node ID values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 common neighbor nodes for nodes `5`
# and `7` (there are no common neighbors)
random_graph %>%
  get_common_nbrs(c(5, 7))
#> [1] NA

# Find all neighbor nodes for nodes `9` and  `17`
random_graph %>%
  get_common_nbrs(c(9, 17))
#> [1] "1"

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.