[R] Re: trailing zeroes
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Feb 26 12:22:01 CET 1999
> Date: Fri, 26 Feb 1999 09:59:39 +0000
> From: Bendix Carstensen <bxc at svs.dk>
> When you require 2 digits you expect to find 5.96 printed
Correction, _you_ expect! Very few computer programs do that. You
cannot `require' two digits by options(digits=2): ?options says
digits: controls the number of digits to print when print-
ing numeric values. It is a suggestion only.
> as 6.0, i.e. a number somewhere between 5.95 and 6.04999999999999.
> This is apparently not always the case for R.
> Why does 0 have a special status as trailing digit?
>
> > options(digits=2)
> > x <- c(59.6,59.4)
> > x
> [1] 60 59
> > x/10
> [1] 6.0 5.9
> > x[1]/10
> [1] 6
Because that is how the ASCII C printing functions work. Ultimately
print() calls sprintf with a %x.yf format. What happens depends on how
that is implemented on your system.
S-PLUS has an option nsmall to format to do precisely this, and there
was a question asking how to do it on s-news today. I have thought for
a while that we need to implement something like this in R: maybe I had
better do it....
--
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