From pmc1 at cornell.edu  Tue Jun  3 03:30:19 2008
From: pmc1 at cornell.edu (pmc1 at cornell.edu)
Date: Tue,  3 Jun 2008 03:30:19 +0200 (CEST)
Subject: [Rd] significant digits (PR#9682)
Message-ID: <20080603013019.7445F282C786@mail.pubhealth.ku.dk>

To reply to my own message, that function wasn't quite right. I think
this one works better:

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<left) {out<-as.character(signif(signum,digits=sigdigs))}
  else if (sigdigs==left & trunc(signum) %% 10 == 0)
{out<-paste(round(signum),".",sep="")}
  else if (sigdigs<=left+right) {out<-format(signum,digits=sigdigs)}
  else {out<-sprintf(paste("%.",sigdigs-left,"f",sep=""),signum)}
  return(noquote(out))
}

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.

Pat Carr



[Rd] significant digits (PR#9682)
pmc1 at cornell.edu