[R] a quick question about "format()"

Tony Plate tplate at acm.org
Tue Sep 18 22:15:05 CEST 2007


runner wrote:
> In the documentation of 'pairs'(package:graphics), within the last example,
> it reads: 
> 
> format(c(r, 0.123456789), digits=3)[1]
> 
> Why not simple use: format(r, digits=3)? What is the difference?

Here are some examples of the difference:

 > for (r in 1.2*10^(-6:9)) cat(format(c(r, 0.123456789), digits=3)[1], 
format(r, digits=3), "\n")
1.20e-06 1.2e-06
0.000012 1.2e-05
0.00012 0.00012
0.0012 0.0012
0.012 0.012
0.120 0.12
1.200 1.2
12.000 12
120.000 120
1200.000 1200
1.20e+04 12000
1.20e+05 120000
1.20e+06 1200000
1.20e+07 1.2e+07
1.20e+08 1.2e+08
1.20e+09 1.2e+09
 >

> 
> Thanks.



More information about the R-help mailing list