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

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jun 12 14:58:41 CEST 2008


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,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list