title: Testing Vector for equality with NAs in subscripts R
body: <p>I discovered a strange behavior in R and wanted to ask whether it can lead to problems.
  Here is an example of what I mean:</p>
  <pre><code>x&lt;-c(1,2,3,4,NA, 5)
  x==1
  x
  </code></pre>
  <p>this returns:</p>
  <pre><code>TRUE FALSE FALSE FALSE    NA FALSE
  </code></pre>
  <p>Now say I want to change all x==1 to 100:</p>
  <pre><code>x[x==1]&lt;-100
  x
  </code></pre>
  <p>returns:</p>
  <pre><code>100   2   3   4  NA   5
  </code></pre>
  <p>So for some reason referencing x with a logical vector with an NA worked. Why?
  To me this behavior of &quot;==&quot; with NAs doesn't make much sense.
  I am also worried now that this kind of assignment x[x==y]&lt;-... may have caused (unnoticed) problems with other types of vectors such as in data.frames or matrices. Has anyone encountered any problems with this or does this logical NA referencing work consistently with other types of vectors?</p>