[Rd] round(#, digits=x) unreliable for x=2 (PR#9682)

2007-05-14 Thread scott . wilkinson
Full_Name: Scott Wilkinson
Version: 2.3.1
OS: WinXP Pro
Submission from: (NULL) (140.253.203.4)


In the example below round() does not report to the specified number of digits
when the last digit to be reported is zero: Compare behaviour for 0.897575 and
0.946251. Ditto for signif(). The number of sigfigs is ambiguous unless the
reader knows this behaviour. Is this a bug or intended behaviour? Is there a
work-around?

#Example code:
number <- 0.897575 # this one isn't reported to 2 decimal places 0.90 as
expected
#number <- 0.946251 # when the last reported digit is non-zero it gives expected
behaviour
Round3 <- round(number, digits=3)
Round2 <- round(number, digits=2)   #why 0.9 and not 0.90 for 0.897575?
Round1 <- round(number, digits=1)

Signif3 <- signif(number, digits=3)
Signif2 <- signif(number, digits=2)#why 0.9 and not 0.90 0.897575?
Signif1 <- signif(number, digits=1)

Results <- data.frame(Round3, Round2, Round1, Signif3, Signif2, Signif1)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] significant digits (PR#9682)

2008-06-12 Thread Scott . Wilkinson
Thanks Patrick, your function is a neat work-around to include trailing
zeroes when specifying significant digits.
It worked better with this modification to the "format" arguments: =20
  else if (sigdigs<=3Dleft+right)
{out<-format(signum,nsmall=3Dsigdigs-left)}

Agree would be nice to include this in signif()
Regards, Scott.

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf=20
> Of Patrick Carr
> Sent: Tuesday, 3 June 2008 11:28 AM
> To: [EMAIL PROTECTED]
> Cc: Wilkinson, Scott (CLW, Townsville)
> Subject: Re: significant digits (PR#9682)
>=20
> To reply to my own message, that function wasn't quite right. I think
> this one works better:
>=20
> signif.string <- function(signum,sigdigs){
>   test <- abs(signum)
>   left <- nchar(trunc(test))
>   right <- nchar(test)-left-1
>   if (test<1) {left<-left-1}
>   if (right<0) {right<-0}
>   if (sigdigs   else if (sigdigs=3D=3Dleft & trunc(signum) %% 10 =3D=3D 0)
> {out<-paste(round(signum),".",sep=3D"")}
>   else if (sigdigs<=3Dleft+right) =
{out<-format(signum,digits=3Dsigdigs)}
>   else {out<-sprintf(paste("%.",sigdigs-left,"f",sep=3D""),signum)}
>   return(noquote(out))
> }
>=20
> But it should still have error checking and vector capability, yadda
> yadda. Also, I forgot what year it was, so sorry, Scott, for spamming
> you with something you're hopefully not still stuck on.
>=20
> Pat Carr
>=20

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel