# NOT RUN {
## Weighted variance
x <- rnorm(30)
w <- runif(30, 0, 1)
varW(x, w)
## Simple variance
varW(x)
stopifnot(varW(x) == var(x))
## NA handling
varW(c(x[1:29], NA), w, na.rm = TRUE) # NA in x (removed)
varW(c(x[1:29], NA), w, na.rm = FALSE) # NA in x (NA returned)
varW(x[1:29], w = c(w[1:29], NA)) # NA in w (NA returned)
# }
Run the code above in your browser using DataLab