Skip to content

Instantly share code, notes, and snippets.

@gluc
Created August 22, 2016 02:32
Show Gist options
  • Save gluc/4e27a90904c68c8bbbe3ae2e00e6f2eb to your computer and use it in GitHub Desktop.
Save gluc/4e27a90904c68c8bbbe3ae2e00e6f2eb to your computer and use it in GitHub Desktop.
library(data.tree)
yaml <- "
campus:
south:
label: campussouth
north:
label: campusnorth
"
lol <- yaml::yaml.load(yaml)
tree <- as.Node(lol)
# dummy data
df <- data.frame(campussouth = 1, campusnorth = 1:10)
# assign data to tree Nodes
for (leaf in tree$leaves) {
leaf$data <- df[leaf$label]
}
#check if data is on the leaf
tree$campus$south$data
#do crazy analytics
tree$Do(function(node) {
if (node$isLeaf) node$max <- max(node$data)
else node$max <- Aggregate(node, "max", max)
}
)
print(tree, "max")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment