Splits the data into subsets, computes summary statistics for each, and returns the result.
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.- 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()
,
metric_var()
,
quantile()
,
scale()
,
variation()
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to a compositional matrix
coda <- as_composition(slides, sample = 2, group = 1)
## Compositional mean by sample
aggregate(coda, by = get_samples(coda), 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
## Compositional mean by group
aggregate(coda, by = get_groups(coda), FUN = mean)
#> quartz microcline plagioclass biotite muscovite opaques
#> A1 0.2680804 0.3506615 0.3267723 0.03302334 0.010447298 0.006724201
#> A2 0.2831265 0.3509840 0.3161602 0.02767572 0.012826283 0.006955211
#> A3 0.2633293 0.3574333 0.3199675 0.03984005 0.009170492 0.008472383
#> A4 0.2725459 0.3590486 0.3181972 0.02652094 0.009552583 0.008424043
#> A5 0.2741411 0.3450908 0.3273973 0.02900410 0.013085565 0.006529511
#> nonopaques
#> A1 0.004290959
#> A2 0.002272084
#> A3 0.001786999
#> A4 0.005710815
#> A5 0.004751617
## Metric variance by group
aggregate(coda, by = get_groups(coda), FUN = metric_var)
#> [,1]
#> A1 0.3916898
#> A2 0.3564152
#> A3 0.4820009
#> A4 0.1381535
#> A5 0.1372695