title: Replace NA with 0 in a data frame column
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/10139284/set-na-to-0-in-r">Set NA to 0 in R</a></p>
  </blockquote>
  
  <p>I have a data.frame with a column having <code>NA</code> values. I want to replace <code>NA</code> with <code>0</code> or any other value. I have tried a lot of threads and methods but it did not give me the result. I have tried the below methods.</p>
  <pre><code>a$x[a$x == NA] &lt;- 0;
  a[ , c(&quot;x&quot;)] &lt;- apply(a[ , c(&quot;x&quot;)], 1, function(z){replace(z, is.na(z), 0)});
  a$x[is.na(a$x), ] &lt;- 0;
  </code></pre>
  <p>None of the above methods replaced <code>NA</code> with 0 in column <code>x</code> for data.frame <code>a</code>. Why?</p>