Obtaining a histogram with frequencies