Hello,
I'm glad it helped.
You should have kept this in the list, the odds of getting more answers
are bigger.
As for your problem with NAs, what do you want to do with them? Should
they count as within range?
Rui Barradas
Em 22-11-2012 10:18, Helene Frigstad escreveu:
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
Many thanks, Helene
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.