Wolfram Fischer - Z/I/M
2003-Feb-06 16:40 UTC
[Rd] signif {base}: changes to scientific notation
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
ripley@stats.ox.ac.uk
2003-Feb-06 16:54 UTC
[Rd] signif {base}: changes to scientific notation
You are confusing signif() and printing! signif() returns a real number. Printing does exactly what it is described to do, and has no concept of how the number was produced. I guess you were looking for format(), which allows more control. On Thu, 6 Feb 2003, Wolfram Fischer - Z/I/M wrote:> 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.This is a misunderstanding of what is happening -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595