title: NA matches NA, but is not equal to NA. Why?
body: <p>In <em>R Language Definition</em>, <code>NA</code> values are briefly described, a portion of which says</p>
  
  <blockquote>
    <p>... In particular, <code>FALSE &amp; NA</code> is <code>FALSE</code>, <code>TRUE | NA</code> is <code>TRUE</code>. <code>NA</code> is not equal to
    any other value or to itself; testing for <code>NA</code> is done using <code>is.na</code>. However, an <code>NA</code> value will match another <code>NA</code> value in <code>match</code>.</p>
  </blockquote>
  
  <p>Regarding the statement  "<code>NA</code> <strong>is not equal to
  any other value or to itself</strong>", </p>
  
  <hr>
  
  <p>Updated: 
  The question, revised again, is  </p>
  
  <p><strong>What is the reasoning, if any, behind</strong> <code>NA</code> <strong>matching</strong> <code>NA</code> <strong>in</strong> <code>match</code>, <strong>and nowhere else in the language?</strong>  </p>
  
  <p>It doesn't make sense to me that a missing value, unknown by anyone (or it would not be missing), would match another missing value of the same type.  Since I posted this, I came across something in <code>example(match)</code> that provides some reasoning. Character coercion changes its type.  I can erase it completely if I like.</p>
  
  <pre><code>match(NA, NA)
  # [1] 1
  match(NA, NA_real_)
  # [1] 1
  match(NA_character_, NA_real_)
  # [1] 1
  match(paste(NA), NA)
  # [1] NA
  gsub("NA", "", NA)
  # [1] NA
  gsub("NA", "", paste(NA))
  # [1] ""
  is.na(NA)
  # [1] TRUE
  is.na(paste(NA))
  # [1] FALSE
  </code></pre>
  
  <p>Apologies for stirring the pot, but some of the documentation is unclear about this.  It might boil down to the R parser/deparser and the fact that you can turn anything into a text character object in R.</p>
  
  <hr>
  
  <p>Original Post:</p>
  
  <p>Now referring to <strong>"However, an</strong> <code>NA</code> <strong>value will match another</strong> <code>NA</code> <strong>value in</strong> <code>match</code>."</p>
  
  <p>If <code>NA</code> is it not equal to itself, why is it matched with itself in <code>match</code>?  and also in <code>identical</code>?  Is this done on purpose? </p>
  
  <pre><code>NA == NA  ## expecting TRUE
  # [1] NA
  NA != NA
  # [1] NA
  x &lt;- NA
  x == x
  # [1] NA
  match(NA, NA)
  # [1] 1
  identical(NA, NA)
  # [1] TRUE
  all.equal(NA, NA)
  # [1] TRUE
  </code></pre>