weighted.mean {stats} | R Documentation |
Compute a weighted mean.
weighted.mean(x, w, ...) ## Default S3 method: weighted.mean(x, w, ..., na.rm = FALSE)
x |
an object containing the values whose weighted mean is to be computed. |
w |
a numerical vector of weights the same length as x giving
the weights to use for elements of x . |
... |
arguments to be passed to or from methods. |
na.rm |
a logical value indicating whether NA
values in x should 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 "POSIXct"
, "POSIXlt"
and
"Date"
. The default method will work for any numeric-like
object for which multiplication and sum
have suitable
methods.
If w
is missing then all elements of x
are
given the same weight, otherwise the weights are normalized to sum to one.
Missing values in w
are not handled.
## GPA from Siegel 1994 wt <- c(5, 5, 4, 1)/15 x <- c(3.7,3.3,3.5,2.8) xm <- weighted.mean(x,wt)