[Rd] significant digits (PR#9682)
pmc1 at cornell.edu
pmc1 at cornell.edu
Tue Jun 3 03:30:19 CEST 2008
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
More information about the R-devel
mailing list