Description Usage Arguments Value Examples
View source: R/weighted_mean.R
weighted_mean()
computes a weighted arithmetic mean. It enhances the
weighted.mean
function with support for NA
values in x
. In
fact, weighted_mean()
excludes element-pair with NA
either from x
or
w
.
1 | weighted_mean(x, w, exclude.Inf = TRUE)
|
x |
A numeric vector. |
w |
A numeric vector of weights the same length as |
exclude.Inf |
Logical. |
A numeric scalar.
1 2 3 4 5 6 7 | x1 <- c(NA, 2, 3, 4, 5)
w1 <- c(5, NA, 3, 2, 1)
weighted_mean(x1, w1)
x2 <- x1[3:5]
w2 <- w1[3:5]
weighted_mean(x2, w2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.