View source: R/weighted.stats.R
weighted.stats | R Documentation |
Calculates the weighted mean and the variance or standard deviation for a given weighted mean.
weighted.stats(x, w, na.rm = FALSE, stats = "mean")
x |
numerical. A vector of values to compute the weighted statistics. |
w |
numerical. A vector of weights with the same length as |
na.rm |
logical. Should |
stats |
character. Which weighted statistic should be returned: "mean", "var" or "sd"? |
Weigths should vary between 0 and 1. If they don't, they are
normalized to sum one. Weights equal to 0 means that the corresponding
values in x
will be omitted from the from the calculation.
Renato A. F. de Lima
x <- c(1,3,4,8)
w <- c(0.2,0.5,0.7,0.9)
mean(x); weighted.stats(x, w)
sd(x); weighted.stats(x, w, stats = "sd")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.