df_to_nest {D3partitionR} | R Documentation |
Transform a dataframe to a nested lists structure (i.e. hierarchical).
Description
Transform a dataframe to a nested lists structure (i.e. hierarchical).
Usage
df_to_nest(data, step_cols, nodes_data = NULL, count_col = "value",
value_cols = NULL, agg_function = sum, na_behavior = "rm")
Arguments
data |
The data frame to convert to the nested structure. It needs to have several comlumns, each ones account for a given step |
step_cols |
vector containing the names of the columns which should be used as steps. The vector should be ordered. ex: c('step1','step2','step3') |
nodes_data |
A named list to add addition informations to each nodes |
count_col |
Number of occurences in this path (succesion of steps). Default: NULL |
value_cols |
Names of the other columns to keep. Default: NULL |
agg_function |
aggregation function to be applied to value_cols.Ex: mean, sum. Default: sum. Weighted version can also be used, the weighting will be done using the counting variable |
na_behavior |
How to deal with missing data ? |
Value
A data.table with the columns specified in count_col, value_cols and one column per step in the path