Suharto Anggono Suharto Anggono
2017-Apr-01 14:10 UTC
[Rd] complex NA's match(), etc: not back-compatible change proposal
I am raising this again. With z <- complex(real = c(0,NaN,NaN), imaginary = c(NA,NA,0)) , results of sapply(z, match, table = z) and match(z, z) are different in R 3.4.0 alpha. I think they should be the same. I suggest changing 'cequal' in unique.c such that a complex number that has both NA and NaN matches NA and doesn't match NaN, as such complex number is printed as NA.
Martin Maechler
2017-Apr-03 11:05 UTC
[Rd] complex NA's match(), etc: not back-compatible change proposal
>>>>> Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org> >>>>> on Sat, 1 Apr 2017 14:10:06 +0000 writes:> I am raising this again. > With > z <- complex(real = c(0,NaN,NaN), imaginary = c(NA,NA,0)) , > results of > sapply(z, match, table = z) > and > match(z, z) > are different in R 3.4.0 alpha. I think they should be the same. > I suggest changing 'cequal' in unique.c such that a > complex number that has both NA and NaN matches NA and > doesn't match NaN, as such complex number is printed as NA. Thank you very much, Suharto, for the reminder. I have committed a change to R-devel yesterday, though your suggestion above had not been 100% clear to me. What I think we want and I decided to commit r72473 | maechler | 2017-04-02 22:23:56 +0200 (Sun, 02 Apr 2017) was to entirely mimic how R format()s and prints() complex numbers: 1) If a complex number has a real or imaginary which is NA then it is formatted / printed as "NA" ==> All such complex numbers should match() i.e. match(), unique(), duplicated() treat such complex numbers as "the same". 2) The picture is very different with (non-NA) NaN: There, R formats and prints NaN+1i or NaN+99i or 0+1i*NaN differently, and [in R-devel only, planned in R 3.4.0 alpha in a day or two!] match(), unique(), duplicated() now treat them as different. The change is more consistent notably does give the same result for match(z,z) and sapply(z, match, table = z) for a variety of z (permutations).
Seemingly Similar Threads
- complex NA's match(), etc: not back-compatible change proposal
- complex NA's match(), etc: not back-compatible change proposal
- complex NA's match(), etc: not back-compatible change proposal
- complex NA's match(), etc: not back-compatible change proposal
- ans[nas] <- NA in 'ifelse' (was: ifelse() woes ... can we agree on a ifelse2() ?)