7
$\begingroup$

I have a few time series that were (for technical reasons) acquired with slightly different time intervals, ranging between 19 and 21 seconds.

Now, I would like to average the values of these different time series over time, so I thought that I could do some sort of interpolation of the values at some regular interval (e.g. each 20 seconds).

Could someone point out a good way to do this?

Thank you

nico

$\endgroup$
7
$\begingroup$

The zoo package is very good at that (as is xts which extends it). The zoo vignettes have e.g. this example:

zr3 <- zooreg(rnorm(9), start=as.yearmon(2000), frequency=12)
zr3
aggregate(zr3, as.yearqtr, mean)

A (regular) series is created with monthly frequency, and the averaged by quarter. It works the very same way for POSIXct objects at much higher granularity; see the vignette. I suspect that the R-SIG-Finance list archives have plenty of related examples too.

$\endgroup$
  • $\begingroup$ Thank you dirk. I suspected zoo would have something on that line, I'll have a look and see if it fits my needs. I assume it would work also for "relative" times? Each of my time series arbitrarily starts at 0s and ends at ~3500s, so I don't have precise dates. $\endgroup$ – nico Oct 28 '10 at 14:42
  • $\begingroup$ I think so for as long as you can compute some indexing -- something the to-be-averaged items have in common. $\endgroup$ – Dirk Eddelbuettel Oct 28 '10 at 14:55
  • 1
    $\begingroup$ Dirk, unfortunately aggregate did not solve my problem, as I want to resample at essentially the same number of points of the original trace. However I found the reglin function in pastecs that does exactly what I need! rgm2.lab.nig.ac.jp/RGM2/R_man-2.9.0/library/pastecs/man/… $\endgroup$ – nico Oct 29 '10 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.