[R] extract certain values from a ts
antonio rodriguez
antonio.raju at gmail.com
Wed Oct 25 11:52:49 CEST 2006
Gabor Grothendieck escribió:
> There was still a typo in this so here it is again:
>
> # Consider the builtin in nhtemp "ts" series
> # Then the runs below above and below the mean are
> r <- rle(as.vector(nhtemp > mean(nhtemp)))
> r
>
> # with the first and last indexes of each
> # runs being given by:
>
> idx.last <- cumsum(r$lengths)
> idx.first <- idx.last - r$lengths + 1
>
> # and the first and last times of each run being
>
> tt <- time(nhtemp)
> cbind(tt[idx.first], tt[idx.last])
>
Dear Gabor,
Many thanks! The last two sentences are a very nice solution
Best regards,
Antonio
More information about the R-help
mailing list