if (FALSE) {
## create random data
nobs <- 10
classLabels <- letters[1:3]
dat = data.frame(
weight = exp(rnorm(nobs)),
household = factor(sample(classLabels, nobs, replace = TRUE))
)
dat
## calculate weights with geometric_mean
geom_weight <- geometric_mean(dat$weight, dat$household)
cbind(dat, geom_weight)
## calculate weights with arithmetic_mean
arith_weight <- arithmetic_mean(dat$weight, dat$household)
cbind(dat, arith_weight)
## calculate weights "by reference"
geometric_mean_reference(dat$weight, dat$household)
dat
}
Run the code above in your browser using DataLab