nest_tree: Convert a data frame to a tree

View source: R/nest-tree.R

nest_treeR 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 id_col column.

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

tibblify documentation built on Nov. 16, 2022, 5:07 p.m.