[R] printing decimal numbers

Thomas Gerds gerds at fdm.uni-freiburg.de
Tue Feb 25 10:21:07 CET 2003


thanks a lot for your answer. i have not enough skills to write my own
print.default routine, though. i thought there should be a user-option
that allows to change the default behaviour.  anyway, whats the idea
of printing 1e-04 instead of 0.0001 and what is the appropriate topic
in the help-pages or faq?

cheers,
tomy

ripley at stats.ox.ac.uk writes:

> 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)
>> [1] "0.00010"
>> 
>> which is also unwanted. 
>> 
>> thanks a lot so far!
>> 
>> tomy
>> 
>> 
>> "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
>> >>
>> >>
>> >>hi,
>> >>
>> >>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           |
>> >>| [1] 1e-04          |
>> >>`--------------------'
>> >>
>> >>i tried the functions format, formatC, ... and changed 
>> >>options()$digits with no success!
>> >>
>> >>thanks for advice,
>> >>tomy
>> >
>> >
>> > Try:
>> >
>> >> formatC(0.0001, format = "f", digits = 4)
>> > [1] "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

-- 
no signature




More information about the R-help mailing list