title: Fill the gaps in raster stack using subsequent layers
body: <p>Suppose I have a raster stack that each layer has data gap in. I want to use the next two layers in the stack to fill the gaps of each layer:</p>
  
  <pre><code>library(raster)
  r1 &lt;- raster(ncol=20,nrow=20, xmn=0, xmx=20, ymn=0,ymx=20)
  r1[] &lt;- 1:20
  r2 &lt;- r3 &lt;- r4 &lt;- r5 &lt;- r1
  set.seed(0)
  r1[sample(1:ncell(r1), size = 20)] &lt;- NA
  r2[sample(1:ncell(r2), size = 30)] &lt;- NA
  r3[sample(1:ncell(r3), size = 10)] &lt;- NA
  r4[sample(1:ncell(r4), size = 18)] &lt;- NA
  r5[sample(1:ncell(r5), size = 18)] &lt;- NA
  
  s &lt;- stack(r1, r2, r3, r4, r5)
  </code></pre>
  
  <p>In this case r2 and r3 will be used to fill the gaps in r1 and so forth.</p>