I’m working on grouping data by whether the value in a column is greater than the given threshold. Here, a group contains continuous data no smaller than a given threshold. I would like to retrieve the first row containing the max value in a group, and if there is only one value in a group, it should be saved directly. As shown in the below picture, suppose the threshold is 0.3, and I want to obtain the records pointed by arrows:
Can it only be achieved by writing a for .. loop?