title: How to calculate rolling bootstrapped values and confidence intervals in R
body: <p>I am new to R and am trying to calculate the bootstrapped standard deviation (sd) and associated standard error within a 30 observation rolling window. The function below performs the rolling window appropriately if I just want sd. But when I add the bootstrap function using the boot package I get the error specified below. I gather that I am trying to store bootstrap results in a vector that isn't the correct size. Does anyone have any advice on how to store just the bootstrapped sd and associated stderror for each window in rows of a new matrix? The goal is to then plot the sd and associated 95% confidence intervals for each window along the timeseries. Thanks in advance for any help.</p>
  
  <pre><code>&gt; head(data.srs)
      LOGFISH
  1  0.8274083
  2  1.0853433
  3  0.8049845
  4  0.8912097
  5  1.3514569
  6  0.8694499
  
  
  ###Function to apply rolling window
  
  rollWin &lt;- function(timeSeries,  windowLength) 
  {
    data&lt;-timeSeries
    nOut &lt;- length(data[, 1]) - windowLength + 1
    out &lt;- numeric(nOut)
    if (length(data[,1]) &gt;= windowLength)
    {
      for (i in 1:nOut) 
        { 
        sd.fun &lt;- function(data,d)sd(data[d], na.rm = TRUE)
        out[i] &lt;- boot(data[i:(i + windowLength - 1), ], sd.fun, R=1000)
        }
    }
    return (list(result=out))
  } 
  
  ###run rolling window function. ex. rollWin(data, windowlength)
  a.temp&lt;-rollWin(data.srs,30)
  
  
  &gt; warnings()
  Warning messages:
  1: In out[i] &lt;- boot(data[i:(i + windowLength - 1), ], sd.fun,  ... :
    number of items to replace is not a multiple of replacement length
  </code></pre>