Learn R Programming

oak (version 0.2.3)

ancestors: Ancestors of a node

Description

The function ancestors returns the ancestors of a node in a given tree.

Usage

ancestors(.node, .tree, include_node = FALSE)

# S3 method for rtree ancestors(.node, .tree, include_node = FALSE)

Arguments

.node

node or character. The node or node label considered.

.tree

A tree.

include_node

logical. If FALSE (the default), .node is not part of the list returned.

Value

A (possibly empty) list of nodes.

Examples

Run this code
# NOT RUN {
## Rooted tree
(tr0 = c_("Bob", "Carl", "Daniel"))
(tr1 = c_("Bill", "Caroline", "Dimitri", "Enoc"))
(tr2 = r_("Alice", s = list(tr0, tr1)))
ancestors("Alice", tr2)
ancestors("Daniel", tr2, include_node = TRUE)

## Unrooted tree
(tr3 = r_(s = list(tr2, c_("Grand-Mother", "Father", "Son"))))
ancestors("Alice", tr3)
ancestors("Alice", tr3, include_node = TRUE)
ancestors("Daniel", tr3)
ancestors("Son", tr3)
ancestors("Son", tr3, include_node = TRUE)

# }

Run the code above in your browser using DataLab