R/weighted_mean.R

Defines functions weighted_total weighted_mean

Documented in weighted_mean weighted_total

# weighted mean (Hajek estimator)
weighted_mean <- function(x, w, na.rm = FALSE)
{
    dat <- .check_data_weights(x, w, na.rm)
    if (is.null(dat))
        NA
    else
        sum(dat$x * dat$w) / sum(dat$w)
}
# weighted total
weighted_total <- function(x, w, na.rm = FALSE)
{
    dat <- .check_data_weights(x, w, na.rm)
    if (is.null(dat))
        NA
    else
        sum(dat$w * dat$x)
}
tobiasschoch/robsurvey documentation built on June 1, 2025, 10:10 p.m.