Rev 65147 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/stats/man/weighted.mean.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2014 R Core Team% Distributed under GPL 2 or later\name{weighted.mean}\alias{weighted.mean}\alias{weighted.mean.default}\title{Weighted Arithmetic Mean}\description{Compute a weighted mean.}\usage{weighted.mean(x, w, \dots)\method{weighted.mean}{default}(x, w, \dots, na.rm = FALSE)}\arguments{\item{x}{an object containing the values whose weighted mean is to becomputed.}\item{w}{a numerical vector of weights the same length as \code{x} givingthe weights to use for elements of \code{x}.}\item{\dots}{arguments to be passed to or from methods.}\item{na.rm}{a logical value indicating whether \code{NA}values in \code{x} should be stripped before the computation proceeds.}}\details{This is a generic function and methods can be defined for the firstargument \code{x}: apart from the default methods there are methodsfor the date-time classes \code{"POSIXct"}, \code{"POSIXlt"},\code{"difftime"} and \code{"Date"}. The default method will work forany numeric-like object for which \code{[}, multiplication, divisionand \code{\link{sum}} have suitable methods, including complex vectors.If \code{w} is missing then all elements of \code{x} are given thesame weight, otherwise the weights coerced to numeric by\code{\link{as.numeric}} and normalized to sum to one (if possible: iftheir sum is zero or infinite the value is likely to be \code{NaN}).Missing values in \code{w} are not handled specially and so give amissing value as the result. However, zero weights \emph{are} handledspecially and the corresponding \code{x} values are omitted from thesum.}\value{For the default method, a length-one numeric vector.}\seealso{\code{\link{mean}}}\examples{## GPA from Siegel 1994wt <- c(5, 5, 4, 1)/15x <- c(3.7,3.3,3.5,2.8)xm <- weighted.mean(x, wt)}\keyword{univar}