[R] Scientific notation
Frederic Schutz
schutz at wehi.EDU.AU
Thu Jul 4 02:40:08 CEST 2002
On Wed, 3 Jul 2002, ripley at stats.ox.ac.uk wrote:
>> I'm writing a load of output to a file using cat(...), but I can't work
>> out how to turn off scientific notation for small numbers. When I
>> originally tried this a while a go I ended up building up a string
>> variable, which is rather clumsy...
>
> You can't in cat. The simplest idea is to use sprintf or formatC.
By the way, is the following result (R 1.5.0 and 1.5.1) expected ? As I
understand the help page (pasted below), format="fg" should not produce
numbers in the scientific format, but :
> formatC(9.4, digits=1, format="fg")
[1] " 9"
> formatC(9.5, digits=1, format="fg")
[1] "1e+01"
> formatC(9.9, digits=1, format="fg")
[1] "1e+01"
> formatC(10, digits=1, format="fg")
[1] "10"
> formatC(10.1, digits=1, format="fg")
[1] "10"
> formatC(10.9, digits=1, format="fg")
[1] "11"
> format: equal to `"d"' (for integers), `"f"', `"e"', `"E"', `"g"',
> `"G"', `"fg"' (for reals), or `"s"' (for strings). Default is
> `"d"' for integers, `"g"' for reals.
>
> `"f"' gives numbers in the usual `xxx.xxx' format; `"e"' and
> `"E"' give `n.ddde+nn' or `n.dddE+nn' (scientific format);
> `"g"' and `"G"' put `x[i]' into scientific format only if it
> saves space to do so.
>
> `"fg"' uses fixed format as `"f"', but `digits' as number of
> significant digits. Note that this can lead to quite long
> result strings, see examples below.
Frédéric
--
Frédéric SCHÜTZ email: schutz at wehi.edu.au
Genetics and Bioinformatics Group
The Walter and Eliza Hall Institute of Medical Research
Phone: +61 3 9345 2627 Fax: +61 3 9347 0852
Post Office
Royal Melbourne Hospital, 3050
Victoria, Australia
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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