Computes the depth of each node in a given tree data frame, assuming a binary tree structure. Requires the tree data frame to contain a logical column `terminal` indicating terminal nodes.

node_depth(tree)

Arguments

tree

A data frame representing a tree, must contain a `terminal` column.

Value

A vector of depths corresponding to each node in the tree.