average | R Documentation |
Calculate the weighted average that maximizes the maximum likelihood estimator
average(x, w = rep(1, length(x)), type = "mean", na.rm = FALSE)
x |
A numeric vector with the values to be averaged. |
w |
A vector of weights of the same length as |
type |
A character string, either: 'mean' or 'L2' (the default),
such that a weighted mean is computed using |
na.rm |
Should |
A numeric value, representing the weighted mean or median
# Create dummy values
x = runif(10,1,100)
w = runif(10,1,10)
# Compute weighted mean
average(x, w, type = 'mean')
# Compute weighted median
average(x, w, type = 'median')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.