Compute a weighted mean.
weighted.mean(x, w, ...) ## S3 method for class 'default': weighted.mean((x, w, ..., na.rm = FALSE))
- an object containing the values whose weighted mean is to be computed.
- a numerical vector of weights the same length as
xgiving the weights to use for elements of
- arguments to be passed to or from methods.
- a logical value indicating whether
xshould be stripped before the computation proceeds.
This is a generic function and methods can be defined for the first argument
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 and
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, as from R 2.11.0 zero weights are handled specially and the corresponding
x values are omitted from the sum.
For the default method, a length-one numeric vector.
Documentation reproduced from R 2.15.3. License: GPL-2.