0

I want to calculate a time-based sliding window in R. My data frame has the columnames: id, rec_time, pupil_x, pupil_y. I want to calculate descriptive statistics for each window. The window size should be 30 seconds, the step size 15 seconds.

I am aware of the function rollapply of the package zoo. But I don´t know how to use the function to create sliding windows by timestamp.

Looking forward to your answer. Thanks!

Mr. T
  • 11,960
  • 10
  • 32
  • 54
  • 1
    Welcome to StackOverflow! It will be much easier to answer your question if we see your data, as well as the expected results. Please see [this link](https://stackoverflow.com/help/mcve) and [this link](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to create a minimal, reproducible example. – tblznbits Sep 04 '18 at 20:42

1 Answers1

0

The function you are looking for is zoo::rollmean()

You can simply apply it using rollmean(x, 30) where 30 is the 30-s sliding window.

I am limited to elaborate more since a reproducible example was not provided.

FMM
  • 1,857
  • 1
  • 15
  • 38