[R] Format wanted...

J Toll jctoll at gmail.com
Sun Mar 25 04:47:41 CEST 2012


On Sat, Mar 24, 2012 at 7:30 PM, Duncan Murdoch
<murdoch.duncan at gmail.com> wrote:
> Do we have a format that always includes a decimal point and a given number
> of significant digits, but otherwise drops unnecessary characters?  For
> example, if I wanted 5 digits, I'd want the following:
>
> Round to 5 digits:
> 1.234567  -> "1.2346"
>
> Drop unnecessary zeros:
> 1.23      -> "1.23"
>
> Force inclusion of a decimal point:
> 1         -> "1."
>

Duncan,

Maybe sprintf() will work for you.  As it's a wrapper for C sprintf,
it should have its functionality.


James



More information about the R-help mailing list