Re: [R] Custom Zero equivalent in R

From: Petr Savicky <savicky_at_praha1.ff.cuni.cz>
Date: Sat, 07 May 2011 09:04:42 +0200

On Fri, May 06, 2011 at 11:49:30AM -0700, Megh Dal wrote:
> Hi all, I am to find some way on how I can tell R to use this small number 10^-20 as zero by default. This means if any number is below this then that should be treated as negative, or if I divide something by any number less than that (in absolute term) then, Inf will be displayed etc.
>
> I have gone?through?the help page of options() function, however could not find anything on how to handle that issue. Can somebody help me on this regards?

Hi.

If you define your own classes of objects, then this can be done in your own R code. This can work also in some other R code, but not in the calls of the compiled functions, which are frequent in R for speed. For example, it will not work in sum(x), mean(x), sqrt(x) unless you prepare your own versions of these functions.

I am not sure, what is the exact definition of a negative number in your arithmetic. Since 10^-30 < 10^-20, should 10^-30 be treated as negative? Then, what is 1/(10^-30)?

If you need the modification for a concrete application, then it is better to design a specialized algorithm for your application, which uses the standard arithmetic and includes explicit tests like abs(x) < 1e-20.

Petr Savicky.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 07 May 2011 - 07:17:30 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 07 May 2011 - 07:20:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive