Title: | Reshape Data Tree |
---|---|
Description: | 'forestry' a series of utility functions to help with reshaping hierarchy of data tree, and reform the structure of data tree. |
Authors: | Jiena McLellan [aut, cre], Michael Condouris [ctb], Sai Im [ctb] |
Maintainer: | Jiena McLellan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-20 03:29:16 UTC |
Source: | https://github.com/jienagu/forestry |
Add children node
add_child(main_tree, x, assign_node)
add_child(main_tree, x, assign_node)
main_tree |
the parent tree to be appended with children node |
x |
xth child |
assign_node |
appended node as child |
reshaped tree with children assigned
assign attributes to node; work with fix_items function
assign_attr(node_from, node_to)
assign_attr(node_from, node_to)
node_from |
assigned attributes from |
node_to |
assigned attributes to |
a node assigned attributes
Sort chidren nodes with certain order
children_sort(input_node, input_order, mismatch_last = T)
children_sort(input_node, input_order, mismatch_last = T)
input_node |
input node |
input_order |
children node order |
mismatch_last |
TRUE: mismatched children nodes are at the bottom; FALSE: mismatched nodes are at the top |
tree with children nodes sorted with certian order
create a tree with assigned name, children and fields
create_nodes(tree_name, add_children_count, ...)
create_nodes(tree_name, add_children_count, ...)
tree_name |
assign name of tree |
add_children_count |
assign number of chidren to this tree |
... |
parameters that will be passed as fields of this tree |
a tree with assigned name, children and fields
create_nodes(tree_name = "tree1", add_children_count = 3, class = c("A", "B", "C"))
create_nodes(tree_name = "tree1", add_children_count = 3, class = c("A", "B", "C"))
create tree appended with each element of input list as a child
create_tree(input_list, node_name)
create_tree(input_list, node_name)
input_list |
input list to be made for a tree |
node_name |
name of the tree |
a tree with each item of the list as each child
cumulative calculation
cumsum_across_level(input_node, attri_name, level_num)
cumsum_across_level(input_node, attri_name, level_num)
input_node |
tree |
attri_name |
name of this cummulative count field |
level_num |
calculate cummulative value cross the level |
tree with cummulative count
calculate cumsum for input level
cumsum_by_level(input_tree, level_num, attri_name)
cumsum_by_level(input_tree, level_num, attri_name)
input_tree |
input tree |
level_num |
level of tree for cumsum |
attri_name |
name of this cummulative count field |
tree with calculated cumsum for input level
Anonymized sample exercise data
data(exercise_df)
data(exercise_df)
a data frame ready to convert to a tree
Jiena Gu McLellan, 2020-05-26
data(exercise_df)
data(exercise_df)
fill missing value of a field across a level with 0
fill_NA_level(input_node, field_name, by_level, fill_with = 0)
fill_NA_level(input_node, field_name, by_level, fill_with = 0)
input_node |
input node |
field_name |
field for this operation |
by_level |
across this level |
fill_with |
fill missing value with this value |
node with NA filled for the input field at input level
assign certain children nodes and fill NA for empty fields
fix_items(fix_vector, input_node)
fix_items(fix_vector, input_node)
fix_vector |
children node names to be assigned |
input_node |
the node to be exapnded with children's names |
a node expanded with certain children nodes
numericalize children numeric name to convert JSON object to JSON array
fixnames(x)
fixnames(x)
x |
input |
unname numeric names list
numericalize children numeric name to convert JSON object to JSON array
pre_get_array(x)
pre_get_array(x)
x |
input list |
unname numeric names list which is prepared to convert to JSON array
Anonymized sample data
data(test_df)
data(test_df)
a data frame ready to convert to a tree
Jiena Gu McLellan, 2020-05-26
data(test_df)
data(test_df)