weighted_ntile: Weighted (ranked) quantiles

View source: R/weighted_ntile.R

weighted_ntileR Documentation

Weighted (ranked) quantiles

Description

Weighted (ranked) quantiles

Usage

weighted_ntile(vector, weights = rep(1, times = length(vector)), n)

Arguments

vector

The vector for which quantiles are desired.

weights

The weights associated with the vector. None should be NA or zero.

n

The number of quantiles desired.

Details

With a short-length vector, or with weights of a high variance, the results may be unexpected.

Value

A vector of integers corresponding to the ntiles. (As in dplyr::ntile.)

Examples

weighted_ntile(1:10, n = 5)
weighted_ntile(1:10, weights = c(rep(4, 5), rep(1, 5)), n = 5)

hutils documentation built on April 13, 2022, 5:23 p.m.