Re: [R] as.numeric(".") returns 0

From: Prof Brian Ripley <>
Date: Thu, 12 Jun 2008 13:58:41 +0100 (BST)

On Thu, 12 Jun 2008, Peter Dalgaard wrote:

> Paul Johnson wrote:
>> In R version 2.7.0 (2008-04-22) as.numeric(".") returns zero.
>>> as.numeric(".")
>> [1] 0
>> This must be a bug. Splus and previous versions of R (<= 2.6.0) return NA,
>> as you might expect.

Depends who is doing the expecting. Americans think '.9' is a number, and everyone thinks '3.' is, so you can leave out numbers before or after the decimal point and have them taken as zero. And POSIX's description of strtod does imply that '.' represents '0.0'.

Note that in (AFAIK) 'Splus' and previous versions of R this depended on the OS, and OSes were not consistent as to what was a number.

>> I'm running R version 2.7.0 (2008-04-22) on Windows XP.
> I suspect that this got fixed along with the "lone sign" issue. I have

Yes, changed (there is no unanimity as to what the rules should be). The R rule now is that you must have at least one digit in a number (not counting the exponent, if there is one).

> R version 2.7.0 Patched (2008-06-12 r45900)
> Copyright (C) 2008 The R Foundation for Statistical Computing
>> as.numeric(".")
> [1] NA
> Warning message:
> NAs introduced by coercion

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 12 Jun 2008 - 14:38:11 GMT

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 Thu 12 Jun 2008 - 15:00:45 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive