[R] extract certain values from a ts

Gabor Grothendieck ggrothendieck at gmail.com
Tue Oct 24 21:06:13 CEST 2006


# Consider the builtin in nhtemp "ts" series
# Then the runs below above and below the mean are
r <- rle(as.vector(nmtemp > 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(Nile)
cbind(tt[idx.first], tt[idx.last])


On 10/24/06, antonio rodriguez <antonio.raju at gmail.com> wrote:
> Hi,
>
> Having several daily wind speed time series I want to extract those
> consecutive days over and below certain values (i.e. 5 < x <8) Don't
> know which funtion to use (aggregate, lapply?) and how to do it.
>
> Thanks in advance
>
> Antonio
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list