[R] printing decimal numbers

Thomas Gerds gerds at fdm.uni-freiburg.de
Mon Feb 24 19:04:04 CET 2003


> 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

-- 
no signature




More information about the R-help mailing list