[Rd] as.numeric - Possible error (PR#870)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
09 Mar 2001 10:46:15 +0100


maechler@stat.math.ethz.ch writes:

> >>>>> "harald" == harald fekjar <harald.fekjar@basalmed.uio.no> writes:
> 
>     harald> In R I get:
>     harald> ---
>     >> as.numeric(" ")
>     harald> [1] 0 
...
> 
> Note that it's also for other ``blank like'' strings :
> 
>  > sapply(c("", " ", "\t", "\n", "\r"), as.numeric)
>        \t \n \r 
>   0  0  0  0  0 
> 
> Without having the time currently to investigate your suggested change,
> I tend to agree.

We fixed the same problem in scan() recently. Particularly insidious
since SPSS codes missing with a single blank when exporting delimited
files...

The problem there was that we used strtod which returns 0 for
nonnumerics (what else can it do?) and then checked the rest of the
field with isBlankString - which was true of course. I'll have a look
and see if as.numeric is similar.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._