[R] printing decimal numbers
ripley at stats.ox.ac.uk
Mon Feb 24 19:40:05 CET 2003
The way to change the behavour of print.default() is to alter the source
code, which you can do as R is Open Source but you may find daunting.
I find sprintf() more useful than formatC(), but your mileage may differ.
In either case you can do as the internals of print.default do, and
calculate the format from the characteristics of the set of numbers
supplied. Just write your own special-pupose format routine.
On Mon, 24 Feb 2003, Thomas Gerds wrote:
> > formatC(0.0001, format = "f", digits = 4)
> works fine for this case. however, i need a way to automatize this,
> i.e. to change the default behaviour of print.default!? how could this
> be done? the problem with applying the above solution to a number
> which is the result of a function, say, is that one has to know
> beforehand the number of digits, since
> > formatC(1e-04,format="f",digits=5)
>  "0.00010"
> which is also unwanted.
> thanks a lot so far!
> "Marc Schwartz" <mschwartz at medanalytics.com> writes:
> >>-----Original Message-----
> >>From: r-help-admin at stat.math.ethz.ch
> >>[mailto:r-help-admin at stat.math.ethz.ch] On Behalf Of Thomas Gerds
> >>Sent: Monday, February 24, 2003 11:01 AM
> >>To: r-help at stat.math.ethz.ch
> >>Subject: [R] printing decimal numbers
> >>this is a very basic question -- sorry for posing it:
> >>how can i force R to print 0.0001 instead of 1e-04???
> >>| > 0.0001 |
> >>|  1e-04 |
> >>i tried the functions format, formatC, ... and changed
> >>options()$digits with no success!
> >>thanks for advice,
> > Try:
> >> formatC(0.0001, format = "f", digits = 4)
> >  "0.0001"
> > Be sure to use the 'format = "f"' argument.
> > See ?formatC
> > HTH,
> > Marc Schwartz
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