title: r calculating rolling average with window based on value (not number of rows or date/time variable)
body: <p>I'm quite new to all the packages meant for calculating rolling averages in R and I hope you can show me in the right direction.</p>
  
  <p>I have the following data as an example:</p>
  
  <pre><code>ms &lt;- c(300, 300, 300, 301, 303, 305, 305, 306, 308, 310, 310, 311, 312,
      314, 315, 315, 316, 316, 316, 317, 318, 320, 320, 321, 322, 324,
      328, 329, 330, 330, 330, 332, 332, 334, 334, 335, 335, 336, 336,
      337, 338, 338, 338, 340, 340, 341, 342, 342, 342, 342)
  correct &lt;- c(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0,
           1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1,
           1, 0, 0, 1, 0, 0, 1, 1, 0, 0)
  df &lt;- data.frame(ms, correct)
  </code></pre>
  
  <p><code>ms</code> are time points in milliseconds and <code>correct</code> is whether a specific action is performed correctly<br>
  (1 = correct, 0 = not correct). </p>
  
  <p>My goal now is that I'd like to calculate the percentage correct (or average) over windows of a set number of milliseconds. As you can see, certain time points are missing and certain time points occur multiple times. I, therefore, do not want to do a filter based on row number. I've looked into some packages such as "tidyquant" but it seems to me that these kind of packages need a time/date variable instead of a numerical variable to determine the window over which values are averaged. Is there a way to specify the window on the numerical value of <code>df$ms</code>?</p>