nest_tree {tibblify} | R Documentation |
Convert a data frame to a tree
Description
Convert a data frame to a tree
Usage
nest_tree(data, id_col, parent_col, children_to)
Arguments
data |
A data frame. |
id_col |
Id column. The values must be unique and non-missing. |
parent_col |
Parent column. Each value must either be missing (for the
root elements) or appear in the |
children_to |
Name of the column the children should be put. |
Value
A tree like data frame.
Examples
df <- tibble::tibble(
id = 1:5,
x = letters[1:5],
parent = c(NA, NA, 1L, 2L, 4L)
)
out <- nest_tree(df, id, parent, "children")
out
out$children
out$children[[2]]$children
[Package tibblify version 0.3.1 Index]