x <- 1:3
w <- 3:1
# Calculate the geometric mean as an arithmetic mean and
# harmonic mean by transmuting the weights.
geometric_mean(x)
arithmetic_mean(x, transmute_weights(0, 1)(x))
harmonic_mean(x, transmute_weights(0, -1)(x))
# Works for nested means, too.
w1 <- 3:1
w2 <- 1:3
fisher_mean(x, w1, w2)
arithmetic_mean(x, nested_transmute(0, c(1, -1), 1)(x, w1, w2))
arithmetic_mean(x, nested_transmute2(0, c(1, -1), 1)(x, w1, w2))
Run the code above in your browser using DataLab