R/wtdvar.R

Defines functions wtdvar

Documented in wtdvar

wtdvar <- function(x, w, na.rm = TRUE){
    if (na.rm){
        isNA <- is.na(x) | is.na(w)
        x <- x[!isNA]
        w <- w[!isNA]
    }
    n <- length(w)
    xbarw <- sum(w*x) / sum(w)
    varw <- n / (n-1) * sum(w * (x-xbarw)^2) / sum(w)
    varw
}

Try the PracTools package in your browser

Any scripts or data that you put into this service are public.

PracTools documentation built on Oct. 21, 2018, 9:04 a.m.