Splits the data into subsets, computes summary statistics for each, and returns the result.
Usage
# S4 method for class 'CompositionMatrix'
aggregate(x, by, FUN, ..., simplify = TRUE, drop = TRUE)
Arguments
- x
A
CompositionMatrix
object.- by
A
vector
or a list of grouping elements, each as long as the variables inx
. The elements are coerced to factors before use (in the sense thatinteraction(by)
defines the grouping).- FUN
A
function
to compute the summary statistics.- ...
Further arguments to be passed to
FUN
.- simplify
A
logical
scalar: should the results be simplified to a matrix if possible?- drop
A
logical
scalar indicating whether to drop unused combinations of grouping values.
Value
A matrix
.
See also
Other statistics:
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## 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)
#> quartz microcline plagioclass biotite muscovite opaques
#> A 0.2591344 0.3553997 0.3335045 0.02654833 0.013683701 0.007173544
#> B 0.2703079 0.3526640 0.3239803 0.03482515 0.008977167 0.006667495
#> C 0.2772923 0.3535327 0.3149545 0.03107089 0.011128347 0.007732587
#> D 0.2757090 0.3548635 0.3138702 0.03298438 0.010338266 0.009093408
#> E 0.2794701 0.3474061 0.3231178 0.02962410 0.010892785 0.006494703
#> nonopaques
#> A 0.004555830
#> B 0.002578014
#> C 0.004288649
#> D 0.003141288
#> E 0.002994409
## Metric variance by slide
aggregate(coda, by = slides$slide, FUN = variance_total)
#> [,1]
#> A 0.2775844
#> B 1.1398564
#> C 0.1356376
#> D 0.7032019
#> E 0.2810018