what cause NA when convert value in r? : <p>In df, has a factor column as below:</p>

<pre><code>q5
A
1
B
1
</code></pre>

<p>i want to convert the <code>A B</code> to <code>0</code><br>
<code>df$q5&lt;-as.character(df$q5)</code></p>

<p><code>df$q5[df$q5!=1]&lt;-0</code></p>

<p>but result is:</p>

<pre><code>q5
NA
1
NA
1
</code></pre>

<p>what's the problem?</p>
