[RESOLVED] Weighted Average formula
I've written a weighted average function from memory...
Code:
Dim numbersAsInteger(numbers.Length) As Integer
Dim weightings(numbers.Length) As Decimal
Dim sum As Decimal
For x As Integer = 0 To numbers.GetUpperBound(0)
Dim parts() As String = numbers(x).ToString.Split(New String() {" {", "}"}, StringSplitOptions.None)
numbersAsInteger(x) = CInt(parts(0))
weightings(x) = CDec(parts(1))
sum += numbersAsInteger(x) * weightings(x)
Next
Return sum / weightings.Sum
numbers is an object array, which will contain something like {1 {1}, 2 {1.5}, 3 {1}, 4 {3.5}, 5 {1}}
so numbersAsInteger will be {1, 2, 3, 4, 5}
and the parallel weightings array will be {1, 1.5, 1, 3.5, 1}
That's my basic understanding of how a weighted average works. Is that correct?
Re: [RESOLVED] Weighted Average formula
That's seems correct:
Weighted Average = sum (Xi*Wi)/Sum(Wi)
Xi the values
Wi the weight
Re: [RESOLVED] Weighted Average formula
Quote:
Originally Posted by
Delaney
That's seems correct:
Weighted Average = sum (Xi*Wi)/Sum(Wi)
Xi the values
Wi the weight
Ok thanks...