s-news
[Top] [All Lists]

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

To: <ntd@stat.ohio-state.edu>, <s-news@wubios.wustl.edu>
Subject: Re: [S] The mysteries of round () and format ()?
From: "Roy Robertson" <rb0ujr@rohmhaas.com>
Date: Mon, 31 Jan 2000 15:11:23 -0500
Sender: owner-s-news@wubios.wustl.edu
For SPlus 2000 it is found on help for format.default(?format.default).
-----Original Message-----
From: ntd@stat.ohio-state.edu <ntd@stat.ohio-state.edu>
To: s-news@wubios.wustl.edu <s-news@wubios.wustl.edu>
Date: Monday, January 31, 2000 10:53 AM
Subject: Re: [S] The mysteries of round () and format ()?


>
>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

-----------------------------------------------------------------------
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>
  • Re: [S] The mysteries of round () and format ()?, Roy Robertson <=