ancestors: Get the ancestors of a node

Description Usage Arguments Value Examples

View source: R/ancestors.R

Description

Get the ancestors of a node

Usage

1
ancestors(id, tree, n = Inf)

Arguments

id

numeric ids of nodes.

tree

a treedf data.frame, with columns id and parent_id at least.

n

number of levels to look up; n=1 gives the parent, n=2 gives the grand-parent, etc.

Value

A vector of ids of the ancestors of the focus node(s).

Examples

1
2
3
4
tree <- data.frame(id=c(1, 2, 3, 4), parent_id=c(NA, 1, 2, 2))
ancestors(3, tree)
ancestors(3, tree, n=1)
ancestors(c(1,4), tree)

jiho/checkboxTreeInput documentation built on June 13, 2020, 10:29 a.m.