[Rd] Re: precision, incorrect(?) tapply() NA's

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 21 Nov 2000 15:51:08 +0100


>>>>> "DJ" == David James <dj@research.bell-labs.com> writes:

{diverted from R-help to R-devel }

    DJ> Summary:

    DJ> I ran into some unexpected behavior in approx() and tapply() that
    DJ> introduced NA's in "clean" data due to (?) numerical accuracy/round
    DJ> off.  The culprit seems to be in match() that coerces it's
    DJ> arguments to character, loosing precision in the process.

yes, definitely!
match() shouldn't do the character coercion!  
==> This is a bug; I'll send a report

	...........

    DJ> Thus match() seems to be introducing the round off as it coerces its 
    DJ> arguments to character:

    >> match
    DJ> function (x, table, nomatch = NA) 
    DJ> .Internal(match(as.character(x), as.character(table), nomatch))

	.......

If you look at R's source { do_match() in src/main/unique.c },
it becomes clear that the .Internal(match(.))
does not rely at all on character inputs,
and

    match <- function (x, table, nomatch = NA) 
	   .Internal(match(x, table, nomatch))

*seems* to work alright.
But, alas, it only *seems*, since the above change
breaks 
       "make check"

more concretely,
     example(relevel)
leads to an error {when the above changed  match() function is used}
which can be diagnosed to  factor(.,.) not working anymore with the changed 
match() function.  I've seen how to fix factor(.,.) as well,
but this is coming involved.

I think that the above change is *really* what we should use,
but we the consequences must be taken care as well.
Expect a fix for R 1.2,
and thank you very much for your useful report!

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._