aggregate {nexus} | R Documentation |
Compute Summary Statistics of Data Subsets
Description
Splits the data into subsets, computes summary statistics for each, and returns the result.
Usage
## S4 method for signature 'CompositionMatrix'
aggregate(x, by, FUN, ..., simplify = TRUE, drop = TRUE)
Arguments
x |
A |
by |
A vector or a list of grouping elements, each as long as the
variables in |
FUN |
A |
... |
Further arguments to be passed to |
simplify |
A |
drop |
A |
Value
A matrix
.
Author(s)
N. Frerebeau
See Also
Other statistics:
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
metric_var()
,
quantile()
,
scale()
,
variation()
Examples
## Create a data.frame
X <- data.frame(
samples = c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
groups = c("X", "X", "X", NA, NA, NA, "Y", "Y", "Y"),
Ca = c(7.72, 7.32, 3.11, 7.19, 7.41, 5, 4.18, 1, 4.51),
Fe = c(6.12, 5.88, 5.12, 6.18, 6.02, 7.14, 5.25, 5.28, 5.72),
Na = c(0.97, 1.59, 1.25, 0.86, 0.76, 0.51, 0.75, 0.52, 0.56)
)
## Coerce to a compositional matrix
Y <- as_composition(X)
## Compositional mean by sample
aggregate(Y, by = get_samples(Y), FUN = mean)
## Metric variance by group
aggregate(Y, by = get_groups(Y), FUN = metric_var)
[Package nexus version 0.2.0 Index]