[R] NaN/NA and sprintf double format

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri May 17 12:55:29 CEST 2002


This is now fixed in R-devel:

> sprintf("%.2f", NA)
Error in sprintf("%.2f", NA) : use format %d or %i for logical objects
> sprintf("%.2f", as.numeric(NA))
[1] "NA"
> sprintf("%.2f", NaN)
[1] "NaN"
> sprintf("%f", NaN)
[1] "NaN"
> sprintf("%f", as.numeric(NA))
[1] "NA"

Note it checks the types too.

On Tue, 14 May 2002, Dirk Eddelbuettel wrote:

>
> With a (late prerelease of) 1.5.0 on Windows, using sprintf on NaN
> yields garbage when the number of decimal is specified while it
> works fine for NA:
>
> > sprintf("%.2f", NA)
> [1] "0.00"
> > sprintf("%.2f", NaN)
> [1] "-1.#J"
>
> Not specifying the decimal precision lets both print garbage:
>
> > sprintf("%f", NaN)
> [1] "-1.#IND00"
> > sprintf("%f", NA)
> [1] "-1.#QNAN0"
>
> Is this a bug or a feature?
>
> Dirk
>
> --
> According to the latest figures, 43% of all signatures are totally worthless.
>
>
>
>
> --
> According to the latest figures, 43% of all signatures are totally worthless.
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help 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-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list