Learn R Programming

RCMIP5 (version 1.2.0)

cmip5.weighted.mean: Alternative weighted mean

Description

Alternative weighted mean

Usage

cmip5.weighted.mean(x, w = rep(1, length(x)), na.rm = TRUE)

Arguments

x
vector of data
w
vector of weights
na.rm
Remove NAs in both data and weights?

Value

Weighted mean of x, using weights d.

Details

The stats version of weighted.mean doesn't handle weights in a very useful way. Specifically, it will remove missing x values, but not missing weights. A fair number of CMIP5 models have NA values in their grid areas, so this will quickly cause problems. This function removes (if na.rm=TRUE) missing observations and weights before computing the weighted mean.

See Also

weighted.mean