Skip to contents

Get neighbors of nodes in a caugi_graph

Usage

neighbors(cg, nodes = NULL, index = NULL)

neighbours(cg, nodes = NULL, index = NULL)

Arguments

cg

A caugi_graph object.

nodes

A vector of node names, a vector of unquoted node names, or an expression combining these with + and c().

index

A vector of node indexes.

Value

Either a character vector of node names (if a single node is requested) or a list of character vectors (if multiple nodes are requested).

Examples

cg <- caugi_graph(
  A %-->% B,
  B %-->% C,
  class = "DAG"
)
neighbors(cg, "A") # "B"
#> [1] "B"
neighbors(cg, index = 2) # "A" "C"
#> [1] "A" "C"
neighbors(cg, "B") # "A" "C"
#> [1] "A" "C"
neighbors(cg, c("B", "C"))
#> $B
#> [1] "A" "C"
#> 
#> $C
#> [1] "B"
#> 
#> $B
#> [1] "A" "C"
#>
#> $C
#> [1] "B"