[R] Irregular time series
Damon Wischik
djw1005 at cam.ac.uk
Mon Jan 27 22:46:08 CET 2003
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.
More information about the R-help
mailing list