title: In raster set NA to zero where other rasters has value in that cell
body: <p>I have 11 big raster files containing about 314578920 cells. Some of these cells contain NA. I want to replace NA to zero if other rasters has value in that particular cell. But cells that contain NA in all rasters should be the same. For example, see the image below:</p>
  
  <p><a href="https://i.stack.imgur.com/a9DcA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a9DcA.jpg" alt="enter image description here"></a></p>
  
  <p>I have created five rasters (top row) to illustrate my question (but actually I have 11 rasters). The output rasters should be like the bottom row rasters.</p>
  
  <p>Replacing all NA's to zero (i.e., using <code>r[is.na(r[])] &lt;- 0</code>) makes the raster so big that the memory cannot handle. Or, omiting NA's does not serve my purpose. Any idea on how to solve this will be highly appreciated.<br>
  Sample code:</p>
  
  <pre><code>library(raster)
  r &lt;- raster(nrow=5, ncol=5) # create empty raster
  r[] &lt;- rnorm(length(r))     # assign random values to each cell
  r[1:5] &lt;- NA                # assign first row with NA
  </code></pre>