Skip to main content

Neighbors of a node

Source: R/queries.R

Description

Nodes adjacent to node by some edge. mode restricts which edge types count: "in" (parents / arrowheads at node), "out" (children / tails at node), "undirected", or "bidirected"; "all" (default) includes every neighbor regardless of edge type.

Usage

neighbors(cg, node, mode = c("all", "in", "out", "undirected", "bidirected"))

Arguments

cg A graph created with cgraph(), of any class.
node Node name.
mode Which edge types to include: "all" (default), "in", "out", "undirected", or "bidirected".

Details

For a PAG, "in", "out", "undirected", and "bidirected" only match definite (circle-free) edges; neighbors joined by a circle mark (o->, o--, o-o) are reported by "all" only.

Value

Sorted character vector of node names.

Examples

dag <- cgraph(A %-->% B, C %-->% B)
neighbors(dag, "B")
#> [1] "A" "C"
neighbors(dag, "B", mode = "in")
#> [1] "A" "C"
neighbors(dag, "A", mode = "out")
#> [1] "B"