title: How to substitute NA by 0 in 20 columns?
body: <p>I want to substitute NA by 0 in 20 columns. I found this approach for 2 columns, however I guess it's not optimal if the number of columns is 20. Is there any alternative and more compact solution?</p>
  
  <pre><code>mydata[,c("a", "c")] &lt;-
          apply(mydata[,c("a","c")], 2, function(x){replace(x, is.na(x), 0)})
  </code></pre>
  
  <p>UPDATE:
  For simplicity lets take this data with 8 columns and substitute NAs in columns b, c, e, f and d</p>
  
  <pre><code>a  b  c  d  e  f  g  d
  1  NA NA 2  3  4  7  6
  2  g  3  NA 4  5  4  Y
  3  r  4  4  NA t  5  5
  </code></pre>
  
  <p>The result must be this one:</p>
  
  <pre><code>a  b  c  d  e  f  g  d
  1  0  0  2  3  4  7  6
  2  g  3  NA 4  5  4  Y
  3  r  4  4  0  t  5  5
  </code></pre>