in reply to Re^2: HOW to calculate the column data
in thread HOW to calculate the column data

The difference is that I divided each value *before* summing them for extra precision. But I'll grant you that it's surely not needed here.

Storing them in an array is also useful if you want to perform more than one operation, especially if the operation requires all the elements (like finding the median).

By the way,
$vals_by_type{ $type }{ count }++;
is less efficient than
++$vals_by_type{ $type }{ count };