Calculate the weighted average