Re: [R] Truncating trailing digits

From: Marc Schwartz <marc_schwartz_at_comcast.net>
Date: Thu, 03 May 2007 14:29:41 -0500

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



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 03 May 2007 - 19:47:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 May 2007 - 20:33:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.