[R] timeseries aggregation by event (zoo, hydrostat, plyr ?)

Jim Lemon drjimlemon at gmail.com
Fri Jan 30 21:53:29 CET 2015


Hi Bastian,
While doing the research for sequential event intervals, I found a
paper by Dr Andreas Eckner, who studies this topic. I suggest you
check his research page:

http://www.eckner.com/research.html

and I would like to know if you find it helpful.

Jim


On Fri, Jan 30, 2015 at 9:52 PM, Bastian Pöschl <bstan0578 at gmail.com> wrote:
> hallo, i search for a possibillity to aggregate a time series by non
> regular periods (events)
>
>  As an example i have a precipitation time series
>
> ## generate some smooth timeseries
> library(zoo)
> library(hydrostats)
>
> ## some example data
> ##  ##  ##  ##
> x.pr <- c(0, 0, 0, 0.2, 0.8, 0.7, 0, 0, 0, 0.6, 0.9, 0.9, 1, 0, 0, 0, 0.08,
> 0.01, 0.09, 0, 0, 0, 0)
> z.pr <- zooreg(x.pr, start=as.POSIXct("2013-01-01 00:00:20"),
> frequency=0.00005)
> zt <- zooreg(rnorm(20000), start=as.POSIXct("2013-01-01
> 00:00:01"),frequency=0.05)
>
> z<-merge(zt, z.pr, all = TRUE)
> Zf<-na.spline(z[,2], na.rm = FALSE)
> Zf[Zf<=0.001]<-0
> ##  ##  ##  ##
> #plot(Zf)
>
> ## i can get the rain events easily with hydrostats package
> P.df<-data.frame(Date=time(Zf),Q=coredata(Zf)) ##data.frame as taken by
> hydrostats
> P.ev<-high.spell.lengths(P.df, threshold=0.1, ind.days = 0) ##spell.length
> will be in 20 secs
> P.ev$end.date<-P.ev$start.date+P.ev$spell.length*20
>
> ## now i want to aggregate data within this events
> ## i need to get min/max/mean value
> ## by now i use window.zoo within a for loop like
>
> for (i in 1:nrow(P.ev)){P.ev$Max[i]<-max((window(P.ev,
> start=P.ev$start.date[i], end=P.ev$end.date[i])),na.rm=TRUE)}
>
> ## but this takes a lot of time within a dacade series
> ## any suggestions how i might speed this up ?
>
> ## i tried aggregate.zoo, ddply but got no simple solution for this...
> ## hydrostats seems to do something like it within the high.spells function
> but the output is just an overall statistic
>
>
> Thank you dear HelpRs
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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