sortGroups function

Sort groups based on a function such as mean value or deviation.