getChildren function

Generate Child and Parent Node Relationships

Generate Child and Parent Node Relationships

Populates childLeft, childRight, and parent columns in the dataset to establish parent-child relationships between nodes based on tree structure.

getChildren(data)

Arguments

  • data: A data frame with tree structure, including iteration, treeNum, node, and depth columns, along with a terminal indicator.

Returns

The modified data frame with childLeft, childRight, and parent columns added, detailing the tree's parent-child node relationships.

Examples

data("tree_data_example") # Create Terminal Column tree_data_example <- transform(tree_data_example, terminal = ifelse(is.na(var), TRUE, FALSE)) # Get depths depthList <- lapply(split(tree_data_example, ~treeNum + iteration), function(x) cbind(x, depth = node_depth(x)-1)) # Turn into data frame tree_data_example <- dplyr::bind_rows(depthList, .id = "list_id") # Add node number sequntially tree_data_example$node <- with(tree_data_example, ave(seq_along(iteration), list(iteration, treeNum), FUN = seq_along)) # get children getChildren(data = tree_data_example)
  • Maintainer: Alan Inglis
  • License: GPL (>= 2)
  • Last published: 2024-07-24

Useful links