Weighted (ranked) quantiles
weighted_ntile(vector, weights = rep(1, times = length(vector)), n)
vector | The vector for which quantiles are desired. |
---|---|
weights | The weights associated with the vector. None should be |
n | The number of quantiles desired. |
A vector of integers corresponding to the ntiles. (As in dplyr::ntile
.)
With a short-length vector, or with weights of a high variance, the results may be unexpected.
weighted_ntile(1:10, n = 5)#> [1] 1 1 2 2 3 3 4 4 5 5#> [1] 1 1 2 3 4 5 5 5 5 5