Generic function to calculate the center of a compositional dataset
center(X, zero.rm = FALSE, na.rm = FALSE)
compositional dataset
a logical value indicating whether zero values should be stripped before the computation proceeds.
a logical value indicating whether NA values should be stripped before the computation proceeds.
X = matrix(exp(rnorm(5*100)), nrow=100, ncol=5)
g = rep(c('a','b','c','d'), 25)
center(X)
#> [1] 0.1890920 0.1968820 0.2096448 0.2013959 0.2029853
(by_g <- by(X, g, center))
#> INDICES: a
#> V1 V2 V3 V4 V5
#> 0.1457880 0.2210387 0.1888548 0.2358188 0.2084997
#> ------------------------------------------------------------
#> INDICES: b
#> V1 V2 V3 V4 V5
#> 0.1937466 0.1649580 0.2455290 0.1957416 0.2000248
#> ------------------------------------------------------------
#> INDICES: c
#> V1 V2 V3 V4 V5
#> 0.2373085 0.1675911 0.2013811 0.2062160 0.1875032
#> ------------------------------------------------------------
#> INDICES: d
#> V1 V2 V3 V4 V5
#> 0.1845654 0.2379347 0.2001768 0.1672419 0.2100812
center(t(simplify2array(by_g)))
#> V1 V2 V3 V4 V5
#> 0.1890920 0.1968820 0.2096448 0.2013959 0.2029853