weightedVar {matrixStats} | R Documentation |
Computes a weighted variance / standard deviation of a numeric vector or across rows or columns of a matrix.
weightedVar(x, w = NULL, idxs = NULL, na.rm = FALSE, center = NULL, ...) weightedSd(...) rowWeightedVars(x, w = NULL, rows = NULL, cols = NULL, na.rm = FALSE, ...) colWeightedVars(x, w = NULL, rows = NULL, cols = NULL, na.rm = FALSE, ...) rowWeightedSds(x, w = NULL, rows = NULL, cols = NULL, na.rm = FALSE, ...) colWeightedSds(x, w = NULL, rows = NULL, cols = NULL, na.rm = FALSE, ...)
x |
a |
w |
a vector of weights the same length as |
idxs, rows, cols |
A |
na.rm |
a logical value indicating whether |
center |
Optional |
... |
Not used. |
The estimator used here is the same as the one used by the "unbiased"
estimator of the Hmisc package. More specifically,
weightedVar(x, w = w) == Hmisc::wtd.var(x, weights = w)
,
Returns a numeric
scalar.
Missing values are dropped at the very beginning,
if argument na.rm
is TRUE
, otherwise not.
Henrik Bengtsson
For the non-weighted variance, see var
.