Calculate the median values for a set of groups