| nestedFunBuilder | R Documentation |
Creates nested list structures by grouping data according to specified factors and optionally applying a function to each final subset. This is the main function for creating hierarchical data structures for analysis.
nestedFunBuilder(data, ..., .fun = identity, .funArgs = list())
data |
a data frame, list, tibble or object coercible by
|
... |
character strings specifying the names of grouping variables
(factors) in |
.fun |
function to apply to each final data subset. Default is
|
.funArgs |
list of additional arguments to pass to |
The function performs the following steps:
Validates that all specified factors exist in the data
Warns about missing factors and removes them from processing
Creates nested subsets using the specified factors
Applies the specified function to each final subset
A nested list structure where each level corresponds to a factor
level. If .fun = identity, returns data subsets. Otherwise, returns
the result of applying .fun to each subset.
## Not run:
# Create nested data structure
nested_data <- nestedFunBuilder(iris, "Species", "Sepal.Length > 5")
# Apply function to each subset
means <- nestedFunBuilder(iris, "Species",
.fun = function(data) mean(data$Sepal.Length)
)
# Multiple factors with function
results <- nestedFunBuilder(mydata, "site", "species", "treatment",
.fun = myAnalysisFunction,
.funArgs = list(method = "robust")
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.