[R] Infinite != NaN?

Michael Hannon jm_hannon at yahoo.com
Sun Aug 30 03:58:44 CEST 2009


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.

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

-----

R version 2.9.2 (2009-08-24)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

-----

$ uname -a
Linux xxxxxxx.localdomain 2.6.29.6-217.2.16.fc11.x86_64 #1 SMP Mon Aug 24 17:17:40 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux




More information about the R-help mailing list