NA matches NA, but is not equal to NA. Why?

前端 未结 2 763
遥遥无期
遥遥无期 2020-12-16 15:38

In R Language Definition, NA values are briefly described, a portion of which says

... In particular, FALSE & NA

2条回答
  •  粉色の甜心
    2020-12-16 16:20

    To add to @farnsy's great answer, and to elaborate on the difference with == and match:

    The key thing to consider is how these two functions (== and match) are used.

    x == y
    translation:  Is the value on the left the same value as the one on the right
    
    match(x, table)
    translation:  Is the value on the left found in the table on the right; 
                  if so, return the index of the FIRST TIME that x appears in table
    

    A common use case I often encounter is working with a set of IDs. Especially, when dealing with two different datasets that have been joined, I might be left with several NAs in one of my ID columns

    However, not all NAs represent the same real life object.

提交回复
热议问题