R: Pruning data.tree without altering
问题 In the data.tree package when one prunes a tree, it permanently alters the tree. This is problematic, as my data.tree takes a long time to generate, and I don't want to generate a new one everytime I have to do a new pruning. Here I generate a data.tree # Loading data and library library(data.tree) data(acme) # Function to add cumulative costs to all nodes Cost <- function(node) { result <- node$cost if(length(result) == 0) result <- sum(sapply(node$children, Cost)) return (result) } # Adding