View source: R/extendr-wrappers.R
| neighbors | R Documentation |
caugiGet neighbors of a node in the graph, optionally filtered by edge direction
or type. This function works for all graph classes including UNKNOWN.
neighbors(cg, nodes = NULL, index = NULL, mode = "all")
neighbours(cg, nodes = NULL, index = NULL, mode = "all")
cg |
A |
nodes |
A character vector of node names. |
index |
A vector of node indexes. |
mode |
Character; specifies which types of neighbors to return:
Not all modes are valid for all graph classes:
|
Either a character vector of node names (if a single node is requested) or a list of character vectors (if multiple nodes are requested).
Other queries:
ancestors(),
anteriors(),
children(),
components(),
descendants(),
districts(),
edge_types(),
edges(),
exogenous(),
is_acyclic(),
is_admg(),
is_ag(),
is_caugi(),
is_cpdag(),
is_dag(),
is_empty_caugi(),
is_mag(),
is_mpdag(),
is_pdag(),
is_simple(),
is_ug(),
m_separated(),
markov_blanket(),
nodes(),
parents(),
posteriors(),
same_nodes(),
spouses(),
subgraph(),
topological_sort()
cg <- caugi(
A %-->% B,
B %-->% C,
class = "DAG"
)
neighbors(cg, "A") # "B"
neighbors(cg, index = 2) # "A" "C"
neighbors(cg, "B") # "A" "C"
neighbors(cg, c("B", "C"))
#> $B
#> [1] "A" "C"
#>
#> $C
#> [1] "B"
# Using mode to filter by edge direction
neighbors(cg, "B", mode = "in") # "A" (parents)
neighbors(cg, "B", mode = "out") # "C" (children)
# Works for UNKNOWN graphs too
cg_unknown <- caugi(
A %-->% B,
B %---% C,
C %o->% D,
class = "UNKNOWN"
)
neighbors(cg_unknown, "B", mode = "in") # "A"
neighbors(cg_unknown, "B", mode = "undirected") # "C"
neighbors(cg_unknown, "C", mode = "partial") # "D"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.