Hi,
yes, that is a very elegant solution. Thank you very much!
Do you have any suggestions on how to deal with NA in such a situation? For example, if I have one missing value in the dataset, then the function will only work until it reaches the NA, and then the rest will be NA as well.
head (D, 11) Salt time310 35.63511 2004-07-17311 35.62334 2004-07-18312 35.63498 2004-07-19313 35.64032 2004-07-20314 NA 2004-07-21315 35.66930 2004-07-22316 35.65394 2004-07-23317 35.64702 2004-07-24318 35.63810 2004-07-25319 35.63190 2004-07-26320 35.66033 2004-07-27
(change <- cumsum(c(FALSE, abs(diff(D$Salt)) > 0.05))) [1] 0 0 0 0 NA NA NA NA NA NA NA
(split(D, change))$`0` Salt time310 35.63511 2004-07-17311 35.62334 2004-07-18312 35.63498 2004-07-19313 35.64032 2004-07-20