s-news
[Top] [All Lists]

Re: rounding

To: <stats@elmo.ch>, "Zheng_Jenny" <Zheng_Jenny@Allergan.com>
Subject: Re: rounding
From: "William Dunlap" <wdunlap@tibco.com>
Date: Mon, 13 Apr 2009 10:33:35 -0700
Cc: <s-news@lists.biostat.wustl.edu>
In-reply-to: <49E1AF7F.3040902@elmo.ch>
References: <37A0A965AB353B4D93AE86C2F16FF382EB0271@IRMAIL134.irvine.allergan.com> <49E1AF7F.3040902@elmo.ch>
Thread-index: Acm7TkP9tTqnNnc0QE+3GQzYGvfnHQBDfU3Q
Thread-topic: [S] rounding
> From: s-news-owner@lists.biostat.wustl.edu 
> [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of 
> Andreas Krause
> Sent: Sunday, April 12, 2009 2:08 AM
> To: Zheng_Jenny
> Cc: s-news@lists.biostat.wustl.edu
> Subject: Re: [S] rounding
> 
> 
> To avoid any machine-dependent arithmetic and keep trailing zeros, 
> converting to characters helps at times.
> 
> The example here would be
> format(c(2.5, 3.5), nsmall=2)
> 
>    Andreas

Since S+ 8.0 there has been an sprintf() function that
lets you use the formatting strings used in the C sprintf()
family of functions.  E.g.,
   > sprintf("$%4.2f", c(1.365, 1.375, 1.385, 1.395, 1.405))
   [1] "$1.36" "$1.38" "$1.39" "$1.40" "$1.41"
This uses the C sprintf function in the machine's native C
library and the rounding results may vary.

> 
> 
> Zheng_Jenny wrote:
> > Hi, everyone,
> > 
> >  
> > 
> > I use function signif to report number since it requires 3 
> significant 
> > numbers in my report.  I have two questions: A) according 
> to Splus help 
> > manual, when rounding off a 5, the two common conventions 
> are to: 1) go 
> > to the higher number, or 2) go to the even digit. The 
> |round| function 
> > obeys convention 2, so |round(2.5)| is |2| and |round(3.5)| 
> is |4|. The 
> > rounding mechanism for |signif| is machine dependent, but 
> most machines 
> > will use the "round to even" rule.  I am wondering if I can select 
> > convention 1 rather than depending on machine.  B) when 
> last digit is 
> > zero, e.g. 3.50, the output will be 3.5, which is not 
> appropriate for my 
> > report.  I am wondering if there is a command I can use so 
> that 3.50 
> > will be reported as 3.50 rather than 3.5.
> > 
> >  
> > 
> > Thanks for your help.
> > 
> >  
> > 
> > Jenny
> > 
> >  
> > 
> >  
> > 
> > This e-mail, including any attachments, is meant only for 
> the intended 
> > recipient and may be a confidential communication or a 
> communication 
> > privileged by law. If you received this e-mail in error, 
> any review, 
> > use, dissemination, distribution, or copying of this e-mail 
> is strictly 
> > prohibited. Please notify the sender immediately of the 
> error by return 
> > e-mail and please delete this message from your system. 
> Thank you in 
> > advance for your cooperation.
> > 
> 
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news
> 

<Prev in Thread] Current Thread [Next in Thread>