Weighted Mean in R (Example)
This tutorial explains how to calculate the weighted mean with the weighted.mean() function in the R programming language.
Example Data
my_values <- c(4, 1, 5, 4, 5, 6, 8, 1) # Create example values my_weight <- c(1, 8, 4, 3, 6, 4, 1, 3) # Create example weights |
my_values <- c(4, 1, 5, 4, 5, 6, 8, 1) # Create example values my_weight <- c(1, 8, 4, 3, 6, 4, 1, 3) # Create example weights
Compute Weighted Mean in R
We can use the weighted.mean function to compute the weighted mean of our example data:
weighted.mean(my_values, my_weight) # Compute weighted mean # 3.633333 |
weighted.mean(my_values, my_weight) # Compute weighted mean # 3.633333
The RStudio console is showing the result: The weighted average of our example data is 3.633333.