[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.


-- Mike

> y <- 2/0

> y
[1] Inf

> is.na(y)

> is.nan(y)

> is.finite(y)

> 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 #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