I find that handling R NA for complex variables is not intuitive:
z <- complex(real = c( 1, 1, NA, NA, NA), imaginary = c(NA, NA, 1, 1, NA)) print(z) #> [1] NA NA NA NA NA Re(z) #> [1] 1 1 NA NA NA Im(z) #> [1] NA NA 1 1 NA unique(z) #> [1] NA Re(unique(z)) #> [1] 1 identical(z[1], z[3]) #> FALSE
Are all of these behaviors the way they were developed? If not, which ones are bugs?
Supply of straw
Here is the offer of straw. I'm not crazy, but this leads to consistent behavior:
It seems that the developers of R decided that conceptually there is only one complex value of NA , but it has many different ideas. These representations are complex numbers with NA in binary representation for the real or imaginary part.
To maintain consistency in this world of “equivalent representations”, if z1 and z2 are two different representations of a complex NA , then f(z1) and f(z2) should return equivalent results for all functions f .
In this case, the above behavior for print(z) and unique(z) is correct.
Other behavior should be as follows:
Re(z) #> [1] NA NA NA NA NA Im(z) #> [1] NA NA NA NA NA Re(unique(z)) #> [1] NA identical(z[1], z[3]) #> TRUE
The only operation that should look at the binary representation of values is identical with single.NA set to FALSE :
identical(z[1], z[3], single.NA = FALSE) #> FALSE