View source: R/weighted_mean.R
weighted_mean | R Documentation |
Functions to calculate a weighted mean or any other metric.
weighted_mean(x, w, na.rm = getOption("na.rm", FALSE))
weighted_median(x, w, na.rm = getOption("na.rm", FALSE))
weighted_Q1(x, w, na.rm = getOption("na.rm", FALSE))
weighted_Q3(x, w, na.rm = getOption("na.rm", FALSE))
weighted_fn(x, w, fun, ...)
x |
vector of values |
w |
weights, length 1 or length of |
na.rm |
a logical to indicate whether empty must be removed from |
fun |
function to apply |
... |
arguments passed on to |
na.rm
This 'certestats' package supports a global default setting for na.rm
in many mathematical functions. This can be set with options(na.rm = TRUE)
or options(na.rm = FALSE)
.
For normality()
, quantile()
and IQR()
, this also applies to the type
argument. The default, type = 7
, is the default of base R. Use type = 6
to comply with SPSS.
x <- c(1:10)
y <- c(1:10)
mean(x)
weighted_mean(x, y)
# essentially equal to:
mean(rep(x, y))
x <- c(0:1000)
y <- c(0:1000)
mean(x)
weighted_mean(x, y)
weighted_median(x, y)
weighted_Q1(x, y)
weighted_Q3(x, y)
weighted_fn(x, y, quantile, c(0.01, 0.99))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.