# Redistribute weights.
x <- 1:6
w <- c(1:5, NA)
f <- factor(rep(letters[1:2], each = 3))
w1 <- c(2, 4)
w2 <- 1:6
harmonic_mean(mapply(harmonic_mean, split(x, f), split(w2, f)), w1)
wr <- grouped(scale_weights)(w2, group = f) * w1[f]
harmonic_mean(x, wr)
Run the code above in your browser using DataLab