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

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

The RStudio console is showing the result: The weighted average of our example data is 3.633333.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top