Compute a weighted mean.
1 2 3 4
an object containing the values whose weighted mean is to be computed.
a numerical vector of weights the same length as
arguments to be passed to or from methods.
a logical value indicating whether
This is a generic function and methods can be defined for the first
x: apart from the default methods there are methods
for the date-time classes
"Date". The default method will work for
any numeric-like object for which
[, multiplication, division
sum have suitable methods, including complex vectors.
w is missing then all elements of
x are given the
same weight, otherwise the weights coerced to numeric by
as.numeric and normalized to sum to one (if possible: if
their sum is zero or infinite the value is likely to be
Missing values in
w are not handled specially and so give a
missing value as the result. However, zero weights are handled
specially and the corresponding
x values are omitted from the
For the default method, a length-one numeric vector.
1 2 3 4
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.