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

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
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,                  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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive