title: How to replace NA to 1 in R?
body: <p>I have tried other's R codes from this websites for similar questions, but none of them worked out, so I am confused. 
  I am basically trying to replace all NA values in the 6th column called"Item4" in the dataset called "my_data1".
  <img src="https://i.stack.imgur.com/adC6i.png" alt="enter image description here"></p>
  
  <p>And those R codes that I have tried so far:</p>
  
  <p><code>b$a[is.na(b$a)] &lt;- 1</code><br>
      <code>with(b, replace(a, is.na(a), 1))</code> </p>
  
  <pre><code>`df[,3:5][is.na(df[,3:5])] &lt;-0`
  df &lt;- na_if(df, 'foo')
  x[c("a", "b")][is.na(x[c("a", "b")])] &lt;- 0
  tidyr::replace_na(x, list(a=0, b=0))#
  </code></pre>
  
  <p>However, none of them work out in my dataset. those NA values simply do not be replaced by codes. </p>
  
  <p>I will be really appreciated if someone could help me with this problem. </p>