Build a decision tree from a path-string data frame
load_tree_df_path.Rd
Constructs a tree from a data frame that is already in memory, where the hierarchy is defined using a path string for each node (e.g., "Root/Branch/Leaf").
Details
This is a core constructor function, typically called by a wrapper
like load_tree_csv_path()
, which handles reading the data from a file.
The node's name is inferred from the last element of its path.
See also
load_tree_csv_path()
to read this format from a file.
Examples
# Create a sample data frame in path format
path_df <- data.frame(
path = c("Root", "Root/Branch1", "Root/Branch1/LeafA", "Root/Branch2"),
rule = c("AND", "OR", NA, NA),
question = c(NA, "Is Branch1 relevant?", "Is LeafA true?", "Is Branch2 true?")
)
# Build the tree
my_tree <- load_tree_df_path(path_df)
print(my_tree)
#> levelName
#> 1 Root
#> 2 ¦--Branch1
#> 3 ¦ °--LeafA
#> 4 °--Branch2