Internal recursive function that creates nested list structures by sequentially grouping data by factors and applying a function to each subset. This is the core engine behind nestedFunBuilder and related functions.
baseFunction(currentData, remainingFactors, fun = identity, funArgs = list())
A nested list structure where each level corresponds to a factor,
or the result of applying fun
to the data subset if no factors remain.
data frame containing the current subset of data to process.
character vector of factor names still to be processed.
function to apply to each final data subset. Default is identity
.
list of additional arguments to pass to fun
.
This function works recursively:
Base case: If no factors remain, applies fun
to the current data
Recursive case: Groups data by the first remaining factor, then calls itself on each subset with the remaining factors