I have an irregular time series, stored as a data frame, in the form Time Bytes 57213.191 20 57213.193 20 57213.300 23 ... ... How should I convert this into a regularly-spaced time series? I have in mind to divide time into equal-sized intervals, and sum the number of Bytes in each interval. I tried this: its.to.ts <- function(times,values,delta=1) { m <- min(times) M <- max(times) mm <- delta*floor(m/delta) MM <- delta*ceiling(M/delta) cuts <- seq(from=mm,to=MM,by=delta) nullvals <- rep(0,length(cuts)-1) nulltimes <- cuts[-1]-delta/2 time.factor <- cut(c(times,nulltimes),cuts,labels=FALSE) dd <- aggregate(c(values,nullvals),by=list(time=time.factor),sum) ts(data=dd$x,start=mm,deltat=delta) } but it is very slow (for a data frame of 102,000 lines, converted into a time series of 130,000 points). Is there a better way? Damon Wischik.
You will find all required tools in the PASTECS library, including regul.screen() and regul.adj() to determine best time step in the regular series (with a maximum number of observations matching those in the initial irregular series), and four different regulation methods: regconst(), reglin(), regspline() and regarea(), all available in the more general regul() function. Best, Philippe Grosjean ...........]<(({?<...............<?}))><............................... ) ) ) ) ) ( ( ( ( ( Dr. Philippe Grosjean ) ) ) ) ) ( ( ( ( ( LOV, UMR 7093 ) ) ) ) ) Station Zoologique ( ( ( ( ( Observatoire Oceanologique ) ) ) ) ) BP 28 ( ( ( ( ( 06234 Villefranche sur mer cedex ) ) ) ) ) France ( ( ( ( ( ) ) ) ) ) tel: +33.4.93.76.38.16, fax: +33.4.93.76.38.34 ( ( ( ( ( ) ) ) ) ) e-mail: phgrosjean at sciviews.org ( ( ( ( ( SciViews project coordinator (http://www.sciviews.org) ) ) ) ) ) ....................................................................... -----Original Message----- From: r-help-admin at stat.math.ethz.ch [mailto:r-help-admin at stat.math.ethz.ch]On Behalf Of Damon Wischik Sent: lundi 27 janvier 2003 10:42 To: r-help at stat.math.ethz.ch Subject: [R] Irregular time series I have an irregular time series, stored as a data frame, in the form Time Bytes 57213.191 20 57213.193 20 57213.300 23 ... ... How should I convert this into a regularly-spaced time series? I have in mind to divide time into equal-sized intervals, and sum the number of Bytes in each interval. I tried this: its.to.ts <- function(times,values,delta=1) { m <- min(times) M <- max(times) mm <- delta*floor(m/delta) MM <- delta*ceiling(M/delta) cuts <- seq(from=mm,to=MM,by=delta) nullvals <- rep(0,length(cuts)-1) nulltimes <- cuts[-1]-delta/2 time.factor <- cut(c(times,nulltimes),cuts,labels=FALSE) dd <- aggregate(c(values,nullvals),by=list(time=time.factor),sum) ts(data=dd$x,start=mm,deltat=delta) } but it is very slow (for a data frame of 102,000 lines, converted into a time series of 130,000 points). Is there a better way? Damon Wischik. ______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>> I have an irregular time series, stored as a data frame, in the form >> Time Bytes >> 57213.191 20 >> 57213.193 20 >> 57213.300 23 >> ... ... >> How should I convert this into a regularly-spaced time series? >> I have in mind to divide time into equal-sized intervals, and sum the >> number of Bytes in each interval. I tried this: ...Philippe Grosjean wrote:> You will find all required tools in the PASTECS library, including > regul.screen() and regul.adj() to determine best time step in the regular > series (with a maximum number of observations matching those in the initial > irregular series), and four different regulation methods: regconst(), > reglin(), regspline() and regarea(), all available in the more general > regul() function.Thank you for the link. As I understand them, none of those regulation methods achieve what I want. I want to divide time into equal-sized intervals, and sum the number of bytes arriving in each interval. I do not want any sort of interpolation of existing values. Those four regulation methods are all different types of interpolation, if I understand correctly. My dataset represents a point arrival process, not a sample of a continuous process; I want to turn the continuous-time point arrival process into a discrete-time point arrival process. I am looking for a function which has the same effect as, but is faster than, this:> its.to.ts <- function(times,values,delta=1) { > m <- min(times) > M <- max(times) > mm <- delta*floor(m/delta) > MM <- delta*ceiling(M/delta) > cuts <- seq(from=mm,to=MM,by=delta) > nullvals <- rep(0,length(cuts)-1) > nulltimes <- cuts[-1]-delta/2 > time.factor <- cut(c(times,nulltimes),cuts,labels=FALSE) > dd <- aggregate(c(values,nullvals),by=list(time=time.factor),sum) > ts(data=dd$x,start=mm,deltat=delta) > }Damon Wischik.