Statistical Summaries
Weighted Mean
Unequal Importance
weighted.mean averages values while giving some positions more influence than others.
Program
Play the script to change the final value's weight and watch the average move.
weighted_mean.R
values <- c(10, 20, 30)
weight_last <-
weights <- c(1, 1, weight_last)
average <- weighted.mean(values, weights)
cat(average, "\n", sep = "")
values <- c(10, 20, 30)
weight_last <-
weights <- c(1, 1, weight_last)
average <- weighted.mean(values, weights)
cat(average, "\n", sep = "")
values <- c(10, 20, 30)
weight_last <-
weights <- c(1, 1, weight_last)
average <- weighted.mean(values, weights)
cat(average, "\n", sep = "")
weighted.mean
`weighted.mean(values, weights)` scales each value by its weight.
weights
A larger weight gives one value more pull on the average.
numeric output
`cat` writes the numeric result without R's vector label.