weighted_mean_in: Weighted Arithmetic Mean for Integer Values and Numeric...

Description Usage Arguments Details Value Examples

View source: R/RcppExports.R

Description

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

Usage

1

Arguments

x

Integer vector of values.

w

Numeric vector of weights.

Details

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).

Value

Numeric value.

Examples

1
2
3
4
5
# weighted_mean_in is typically much faster than weighted.mean
x <- rpois(1000, lambda = 5)
w <- runif(1000)
all.equal(weighted.mean(x, w), weighted_mean_in(x, w))
benchmark(weighted.mean(x, w), weighted_mean_in(x, w), replications = 2000)

dvmisc documentation built on May 2, 2019, 5:51 p.m.