# [Rd] signif {base}: changes to scientific notation

Wolfram Fischer - Z/I/M wolfram@fischer-zim.ch
Thu Feb 6 16:40:03 2003

PROBLEM
`signif' does change to scientic notation
at different levels depending on the number
of significant digits in the input.

This can generate tables where figures change
``irregularly'' from normal to scientific notation.

PROPOSAL
The change to the scientific notation should
be made only if the figure in scientific notation
- with potentially as many significant digits as
given as argument to the call of `signif' -
would be shorter than the figure in normal notation.

EXAMPLE

test.signif <- function( d=2, n=9 ){
for( i in 1:n )
cat( paste( sep='\t'
, i
, signif( 10^i * 1     , d )
, signif( 10^i * 1.2   , d )
, signif( 10^i * 1.23  , d )
, signif( 10^i * 1.234 , d )
)
, '\n'
)
}

> test.signif(4)
1       10      12      12.3      12.34
2       100     120     123       123.4
3       1000    1200    1230      1234
4       10000   12000   12300     12340
5       1e+05   120000  123000    123400
6       1e+06   1200000 1230000   1234000
7       1e+07   1.2e+07 12300000  12340000
8       1e+08   1.2e+08 1.23e+08  123400000
9       1e+09   1.2e+09 1.23e+09  1.234e+09

I would expect/propose that the scientific notation in this
example with 4 significant digits begins only at line 9 in
all columns.

Wolfram