weighted_mean_nn: Weighted Arithmetic Mean for Numeric Values and Numeric...

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/functions.R

Description

Written in C++, this function should always run faster than weighted.mean.

Usage

1

Arguments

x

Numeric vector of values.

w

Numeric vector of weights.

Details

NA

Value

Numeric value.

Note

For optimal speed, choose the version of this function that matches the class of your x and w:

weighted_mean_nn for numeric x, numeric w
weighted_mean_ni for numeric x, integer w
weighted_mean_in for integer x, numeric w
weighted_mean_ii for integer x, integer w

These functions typically execute several times faster than the base R function weighted.mean and weighted average functions in other packages (e.g. wtd.mean in Hmisc and wt.mean in SDMTools).

Author(s)

Dane R. Van Domelen

References

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

NA

Examples

1
2
3
4
5
6
7
# weighted_mean_nn is typically much faster than weighted.mean
x <- rnorm(1000)
w <- runif(1000)
all.equal(weighted.mean(x, w), weighted_mean_nn(x, w))
microbenchmark(weighted.mean(x, w),
               weighted_mean_nn(x, w),
               times = 100)

dvmisc documentation built on Dec. 29, 2017, 3:01 a.m.