[R] number format

Thomas Lumley tlumley at u.washington.edu
Fri Dec 31 00:57:16 CET 2004


On Fri, 31 Dec 2004, dax42 wrote:

> This mailing list truly is amazing.
>
> Thank you so much for all the help!
>
> I feel a little strange asking something that "simple" again, but I wasn't 
> able to find it in the help...
>
> Is there a way to tell R how to display numbers (double)? How many numbers 
> after the decimal point, etc...
>

Yes. print() has a digits= option, and there are global options that affec 
the number of digits

Eg:
> micropi<-pi*1e-6
> nanopi<-pi*1e-9
> megapi<-pi*1e6
> gigapi<-pi*1e9
> options("digits")
$digits
[1] 7
> options("scipen")
$scipen
[1] 0
> pi
[1] 3.141593
> micropi
[1] 3.141593e-06
> nanopi
[1] 3.141593e-09
> megapi
[1] 3141593
> gigapi
[1] 3141592654
>
> options(digits=4)
> pi
[1] 3.142
> micropi
[1] 3.142e-06
> nanopi
[1] 3.142e-09
> megapi
[1] 3141593
> gigapi
[1] 3.142e+09
> options(scipen=4)
> pi
[1] 3.142
> micropi
[1] 0.000003142
> nanopi
[1] 3.142e-09
> megapi
[1] 3141593
> gigapi
[1] 3141592654


 	-thomas




More information about the R-help mailing list