Splits the data into subsets, computes summary statistics for each, and returns the result.
# S4 method for CompositionMatrix
aggregate(x, by, FUN, ..., simplify = TRUE, drop = TRUE)# S4 method for GroupedComposition
aggregate(x, FUN, ..., simplify = TRUE)
A matrix
.
A CompositionMatrix
object.
A vector
or a list of grouping elements, each as long as the
variables in x
(see group()
).
A function
to compute the summary statistics.
Further arguments to be passed to FUN
.
A logical
scalar: should the results be simplified to a
matrix if possible?
A logical
scalar indicating whether to drop unused
combinations of grouping values.
N. Frerebeau
Other statistics:
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## Data from Aitchison 1986
data("slides")
## Coerce to a compositional matrix
coda <- as_composition(slides)
## Compositional mean by slide
aggregate(coda, by = slides$slide, FUN = mean)
## Metric variance by slide
aggregate(coda, by = slides$slide, FUN = variance_total)
Run the code above in your browser using DataLab