Constructing a frequency distribution for grouped data