Skip to content
Back to formatted view

Raw Message

Message-ID: <XFMail.030605141223.Ted.Harding@nessie.mcc.ac.uk>
Date: 2003-06-05T13:27:19Z
From: (Ted Harding)
Subject: Max sig figs as well as Min in print?

Hi Folks,

Consider the following example (artificial, but it illustates the point):

  > r2<-sqrt(2)
  > x<-2-r2*r2

  > print(c(pi,sqrt(pi)),digits=5)
  [1] 3.1416 1.7725


  > print(c(pi,sqrt(pi),x),digits=5)
  [1]  3.1416e+00  1.7725e+00 -4.4409e-16

whereas I would prefer

  [1] 3.1416 1.7725 0.0000

which could be achieved by

  > print(c(pi,sqrt(pi),round(x)),digits=5)
  [1] 3.1416 1.7725 0.0000

if need be.

The above of course is due to the definition of "digits" as the miniumum
number of significant figures to print. In order to avoid the behaviour of
the second "print" and make it like the last line, one would need to be
able to set somthing like "maxdigits=5" as well as "digits=5".

Is anything of this sort possible (apart from anticipating the situation
and wrapping relevant computations in "round")?

Thanks, and best wishes,
Ted.