From murdoch at stats.uwo.ca  Mon May 14 12:44:45 2007
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Mon, 14 May 2007 06:44:45 -0400
Subject: [Rd] round(#, digits=x) unreliable for x=2 (PR#9682)
In-Reply-To: <20070514004645.808F42A3F9@slim.kubism.ku.dk>
References: <20070514004645.808F42A3F9@slim.kubism.ku.dk>
Message-ID: <46483D9D.1030504@stats.uwo.ca>

On 13/05/2007 8:46 PM, scott.wilkinson at csiro.au wrote:
> Full_Name: Scott Wilkinson
> Version: 2.3.1
> OS: WinXP Pro
> Submission from: (NULL) (140.253.203.4)
> 
> 
> In the example below round() does not report to the specified number of digits
> when the last digit to be reported is zero: Compare behaviour for 0.897575 and
> 0.946251. Ditto for signif(). The number of sigfigs is ambiguous unless the
> reader knows this behaviour. Is this a bug or intended behaviour? Is there a
> work-around?

It's not a bug.  It has nothing to do with round(), it is the way R 
prints numbers by default.  If you ask to print 0.90, you'll get

[1] 0.9

because 0.9 and 0.90 are the same number.  If you want trailing zeros to 
print, you need to specify a format to do that, e.g.

 > noquote(format(0.9, nsmall=2))
[1] 0.90

The noquote stops the "" from printing.  You could also use sprintf() or 
formatC() for more C-like format specifications.

Duncan Murdoch



[Rd] round(#, digits=x) unreliable for x=2 (PR#9682)
Duncan Murdoch