title: Replacing values in xts object avoiding subscript out of bounds error
body: <p>I have an <code>xts</code> object</p>
  
  <pre><code>library(xts)
  A &lt;- xts(c(1,NA,NA,NA,1,NA,NA,NA,NA,1,NA), Sys.Date()-11:1)
  colnames(A) &lt;- c("A")
  </code></pre>
  
  <p>What I need is: every time we observe a 1 in A, then </p>
  
  <ol>
  <li>The next two days should contain also a 1 (the next day here means the next row).</li>
  <li>The third day after we observe a 1 should be a zero.</li>
  </ol>
  
  <p>So the result should look like</p>
  
  <pre><code>&gt; A
                A
  2014-12-28    1
  2014-12-29    1
  2014-12-30    1
  2014-12-31    0
  2015-01-01    1
  2015-01-02    1
  2015-01-03    1
  2015-01-04    0
  2015-01-05   NA
  2015-01-06    1
  2015-01-07    1
  </code></pre>
  
  <p>What I have tried is</p>
  
  <pre><code>dates.with.1 &lt;- which(A==1)
  A[dates.with.1 + 1] &lt;- 1
  A[dates.with.1 + 2] &lt;- 1
  A[dates.with.1 + 3] &lt;- 0
  </code></pre>
  
  <p>Which gives me </p>
  
  <pre><code>Error in `[.xts`(x, i, which.i = TRUE) : subscript out of bounds
  </code></pre>
  
  <p>since adding the second 1 is not possible at the end of A.</p>