# Load the data.tree package library(data.tree) # Read the CSV file into R my_data <- read.csv("mydata.csv") # Convert the data frame to a tree structure my_data$pathString <- paste("world", my_data$Level_1, my_data$Level_2, my_data$Level_3, sep = "/") my_tree <- as.Node(my_data) # Print the tree Cost <- function(node) { result <- node$Value if(length(result) == 0) result <- sum(sapply(node$children, Cost)) return (result) } my_tree$Do(function(node) node$Value <- Cost(node), filterFun = isNotLeaf) #my_tree$Do(function(node) node$cumValue <- Cumulate(node, attribute = "Value",aggFun = sum)) print(my_tree, "Value","FCU","Cost","Test")