[R] Infinite != NaN?

David Winsemius dwinsemius at comcast.net
Sun Aug 30 04:31:24 CEST 2009


It is not clear that you have read the help page that arise with:

  ?Inf

"Note:

In R, basically all mathematical functions (including basic  
Arithmetic), are supposed to work properly with +/- Inf and NaN as  
input or output.

The basic rule should be that calls and relations with Infs really are  
statements with a proper mathematical limit."

Also:

 > Inf+Inf
[1] Inf
 > Inf-Inf
[1] NaN
 > -2/0
[1] -Inf
 > Inf*Inf
[1] Inf
 > Inf*(-Inf)
[1] -Inf

On Aug 29, 2009, at 9:58 PM, Michael Hannon wrote:

> Greetings.  I somehow had the impression that an infinite number, as  
> obtained by dividing by zero, for instance, would be flagged as both  
> missing ("NA") and not a number ("NaN").  It appears that I was  
> wrong on both counts, although the is.finite function correctly  
> returns FALSE in such a case.  Please see the appended for some  
> details.  I guess that the bottom line is that R works the way it  
> works, but if you can add anything that will further instruct me,  
> I'd appreciate it.
>

So I suppose the obvious further instruction is to read the help pages.

> Thanks.
>
> -- Mike
>
>
>> y <- 2/0
>
>> y
> [1] Inf
>
>> is.na(y)
> [1] FALSE
>
>> is.nan(y)
> [1] FALSE
>
>> is.finite(y)
> [1] FALSE
>
>> z <- log(-1)
> Warning message:
> In log(-1) : NaNs produced
>
>> z
> [1] NaN
>
>> is.nan(z)
> [1] TRUE
>
>> is.na(z)
> [1] TRUE
>
> -----



David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list