s-news
[Top] [All Lists]

Re: [S] The mysteries of round() and format()?

To: s-news@wubios.wustl.edu
Subject: Re: [S] The mysteries of round() and format()?
From: Nicole DePriest <ntd@stat.ohio-state.edu>
Date: Mon, 31 Jan 2000 10:19:40 -0500 (EST)
In-reply-to: <Pine.GSO.4.05.10001310735560.533-100000@auk.stats>
Sender: owner-s-news@wubios.wustl.edu
Out of curiosity, where is the nsmall= option mentioned?  I couldn't find
it in the help files for format, round, ceiling or options and didn't
notice it in the examples in the help files.

Nicole DePriest
______________________________________________________________________________
Nicole DePriest
Statistics Department
The Ohio State University
1958 Neil Ave., #404
Columbus, OH 43210, USA
(614) 292-6038
ntd@stat.mps.ohio-state.edu

On Mon, 31 Jan 2000, Prof Brian D Ripley wrote:

> 
> On Sun, 30 Jan 2000, Paul Schwarz wrote:
> 
> > 
> > Hi S-news readers,
> > 
> > I've been trying to use the round() function along the key() function to
> > display regression coefficients in the legend for a plot.  I'd like to
> > make sure that all the numbers are formatted to 3 decimal places so that
> > the numbers all line up in the legend columns.  Unfortunately, the
> > round() function does not do what I thought it would do (or at least not
> > what I'd like it to do).  For example:
> > 
> > > round(2,3)
> > [1] 2   # what I'd like is 2.000
> 
> > > round(2.0202,3)
> > [1] 2.02  # what I'd like printed is 2.020
> 
> Careful. Round does do what one would expect: it is the printing that is
> supressing the trailing zeroes. key() needs a character string, and will
> use as.character (which can be different again).
> 
> > I've also tried usin the format() function -- also without success.  How
> > do I force the S-PLUS to print the numbers with the 3 decimal places
> > (including a trailing zero if need be) so that my number will line up in
> > my legend?
> 
> Use nsmall in format as in
> > format(round(2, 3), nsmall=3)
> [1] "2.000"
> > format(round(2.02, 3), nsmall=3)
> [1] "2.020"
> 
> -- 
> 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 272860 (secr)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> 


-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

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