[R] Truncating trailing digits
Marc Schwartz
marc_schwartz at comcast.net
Thu May 3 21:29:41 CEST 2007
On Thu, 2007-05-03 at 12:14 -0400, Pietrzykowski, Matthew (GE, Research)
wrote:
> Hello,
>
> I am relatively new to R and have a rudimentary question, I think. How
> does one
> truncate the number of digits displayed after the decimal when viewing
> the results
> of analyses?
>
> My apologies if this question has been answered previously, I was not
> able to find
> references very easily.
>
> Thank you in advance,
>
> Matt
The answer is "it depends".
There are user configurable options in R that determine how default
output is displayed, relative to the number of significant digits and
the use of scientific notation.
See ?options for more information, specifically 'digits' and 'scipen'.
These don't necessarily guarantee a fixed number of digits after the
decimal however.
If you are creating your own output functions and want greater control
over the formatting (ie. column alignment, etc.), including specifically
the number of digits after the decimal, then see ?formatC and ?sprintf
which allow for this. Also see ?cat which is how much of standard R
console output is generated.
HTH,
Marc Schwartz
More information about the R-help
mailing list