Description Usage Arguments Details See Also Examples
View source: R/weighted-stats.r
Compute a weighted variance or standard deviation of a vector.
1 2 3 | weighted.var(x, w = NULL, na.rm = FALSE)
weighted.sd(x, w, na.rm = TRUE)
|
x |
numeric vector of observations |
w |
integer vector of weights, representing the number of
time each |
na.rm |
if |
Note that unlike the base R var
function, these functions only
work with individual vectors not matrices or data frames.
Other weighted statistics: weighted.ecdf
;
weighted.quantile
1 2 3 4 5 6 7 | x <- c(1:5)
w <- rpois(5, 5) + 1
y <- x[rep(seq_along(x), w)]
weighted.var(x, w)
var(y)
stopifnot(all.equal(weighted.var(x, w), var(y)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.