R/wtdVar.r

wtdVar <- function ( x , weights , na.rm = FALSE) {
    if (na.rm) {
      na <- is.na(x) | is.na(weights)
      x <- x[!na]
      weights <- weights[!na]
    }
    out <- sum(weights * (x - weighted.mean(x, weights)) ^ 2) / (sum(weights) - 1)
    return(out)}

Try the eatTools package in your browser

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

eatTools documentation built on Nov. 23, 2023, 5:06 p.m.