wt_stats: Compute basic weighted statistics

wt_statsR Documentation

Compute basic weighted statistics

Description

Functions for computing basic weighted statistics. These functions are designed to be strict, consistent, and useful within dplyr::summarize().

Usage

wt_sum(x, wt)

wt_mean(x, wt)

wt_median(x, wt)

wt_quantile(x, wt, n)

Arguments

x

A logical or numeric vector.

wt

A numeric vector of weights the same length as x.

n

A numeric vector of length one (i.e., a number) giving the number of equally sized groups to split x into. Note that for n groups, there are n - 1 quantiles (i.e., cut points). Quantiles currently supported include the median (n = 2), quartiles (n = 4), quintiles (n = 5), deciles (n = 10), and ventiles (n = 20).

Details

If any NA values are present in x or wt, these functions will return NA.

wt must not contain any negative values. wt may contain values of zero but must not only contain values of zero.

Value

For all except wt_quantile(), a numeric vector of length one.

For wt_quantile(), a named numeric vector of length n - 1 unless any NA values are present in x or wt, in which case a numeric vector of length one (containing NA) is returned.


CenterOnBudget/Rcbpp documentation built on Jan. 6, 2025, 9:32 p.m.