Skip to contents

Get ancestors of nodes in a caugi_graph

Usage

ancestors(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"
)
ancestors(cg, "A") # NULL
#> NULL
ancestors(cg, index = 2) # "A"
#> [1] "A"
ancestors(cg, "B") # "A"
#> [1] "A"
ancestors(cg, c("B", "C"))
#> $B
#> [1] "A"
#> 
#> $C
#> [1] "A" "B"
#> 
#> $B
#> [1] "A"
#>
#> $C
#> [1] "A" "B"