View source: R/weighted_stats.R
weighted_tabulate | R Documentation |
Computes the sum of w
grouped by bin
.
If w
is missing the result is equivalent to
tabulate(bin, nbins)
weighted_tabulate(bin, w, nbins = max(1L, bin, na.rm = TRUE))
bin |
An integer vector with values from |
w |
Weights per entry in |
nbins |
Number of bins |
A vector with length nbins
where the i
th result is equal to
sum(w[bin == i])
or sum(bin == i)
if w
is missing.
For integer weights, this is equivalent to tabulate(rep(bin, w), nbins)
.
Other weighted statistics:
weighted_moments()
,
weighted_quantile()
weighted_tabulate(c(1, 1, 2))
weighted_tabulate(c(1, 1, 2), nbins = 3L)
weighted_tabulate(c(1, 1, 2), w = c(0.5, 0.5, 1), nbins = 3L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.