The method works only when the dataset is sorted by groups.
The method works only when the dataset is sorted by groups.