title: How to calculate input values from a vector of rolling sums in R
body: <p>I have a unique problem where I need to calculate input values behind a vector of rolling sums. For example, I have an hourly data feed from a sensor as follows:</p>
  <pre><code>library(RcppRoll)
  library(dplyr)
  library(lubridate)
  set.seed(123)
  
  df &lt;- data.frame(datetime = seq(as.POSIXct(&quot;2022-01-01 01:00:00&quot;), 
                                  as.POSIXct(&quot;2022-01-10 23:00:00&quot;), by = &quot;hour&quot;), 
                   val = round(runif(239, 0, 40), 0)) %&gt;% 
    mutate(day = day(datetime)) %&gt;% 
    mutate(roll_sum = roll_sum(lag(val), 24, align = &quot;right&quot;, fill = NA))
  </code></pre>
  <p>What I want to do is to calculate <code>predicted values</code> from the <code>roll_sum</code> column. Because in the actual dataset, only rolling sums are available.</p>
  <p>Thank you very much for your time.</p>