Skip to contents

Get the induced subgraph

Usage

subgraph(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

A new caugi_graph that is a subgraph of the selected nodes.

Examples

cg <- caugi_graph(
  A %-->% B,
  B %-->% C,
  class = "DAG"
)
sub_cg <- subgraph(cg, c("B", "C"))
cg2 <- caugi_graph(B %-->% C, class = "DAG")
all(nodes(sub_cg) == nodes(cg2)) # TRUE
#> [1] TRUE
all(edges(sub_cg) == edges(cg2)) # TRUE
#> [1] TRUE