weighted_mean: Weighted arithmetic mean

Description Usage Arguments Value Examples

View source: R/weighted_mean.R

Description

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.

Usage

1
weighted_mean(x, w, exclude.Inf = TRUE)

Arguments

x

A numeric vector.

w

A numeric vector of weights the same length as x giving the weights.

exclude.Inf

Logical.

Value

A numeric scalar.

Examples

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)

ylwpaopao/cnquant documentation built on Dec. 2, 2019, 10:39 p.m.