[R] unexpected result from format(x, digits)

Duncan Murdoch murdoch.duncan at gmail.com
Thu Apr 29 00:52:27 CEST 2010


On 28/04/2010 6:48 PM, Steve Taylor wrote:
> Ted wrote:
>   
>> In the second, 0.08953 rounds (to 2 significant digits) to 0.090,
>> which can be printed without further loss of precision as 0.09
>> while giving the other numbers 2 significant digits.
>>     
> I guess I'm disagreeing with the idea of dropping the trailing zero.  It should be retained, since 2 significant figures was what was asked for.

Then it wouldn't be behaving as documented:  "Numeric vectors are 
encoded with the minimum number of decimal places needed to display all 
the elements to at least the |digit| significant digits. However, if all 
the elements then have trailing zeroes, the number of decimal places is 
reduced until at least one element has a non-zero final digit; see also 
the argument documentation for |big.*|, |small.*| etc, above. "

Duncan Murdoch



More information about the R-help mailing list