Calculating the mean from frequency tables