R-beta: quantile

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Fri, 27 Feb 1998 15:39:20 +0100


>>>>> "PD" == Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

    PD> Martyn Plummer <plummer@iarc.fr> writes:
    >> What about just using format(100*probs)?
    >> 
    R> foo <- function(probs) paste(format(100 * probs), "%", sep="")
    R> foo(c(0.02,0.25,0.50))
    >> [1] " 2%" "25%" "50%"
    R> foo(c(0.025,0.25,0.50))
    >> [1] " 2.5%" "25.0%" "50.0%"
    R> foo(c(0.0125,0.25,0.50))
    >> [1] " 1.25%" "25.00%" "50.00%"
    >> 
    >> I am probably missing something but this seems to be "smart" enough.


    PD> I can do one better, I think:

    >> sapply(c(0.1,2.5,25),format)
    PD> [1] "0.1" "2.5" "25"
    >> foo <- function(probs) paste(sapply(100 * probs,format), "%",
    >> sep="") foo(c(0.02,0.25,0.50))
    PD> [1] "2%" "25%" "50%"
    >> foo(c(0.025,0.25,0.50))
    PD> [1] "2.5%" "25%" "50%"
    >> foo(c(0.0125,0.25,0.50))
    PD> [1] "1.25%" "25%" "50%"

Yes, this is better;
but it actually ``the same'' as  formatC !

[TEACHER:]
   One of the main differences between format(.) and formatC(.)
   is that  format(.) formats a vector into a  COMMON format
   (hence the "50.00%" in Martyn's answer)
   whereas  formatC(.) formats each element INDIVIDUALLY
which is what Peter proposed by
	 sapply(...., format)

formatC however runs the loop in C code rather than interpreted language,
hence my original proposals :

MM> Some untested proposals for replacement of
MM>         round(100 * probs)
MM> 
MM> 1)  formatC(100*probs, dig=3,                            format='f')
MM> 2)  formatC(100*probs, dig= max(3, .Options$digits - 3), format='f')
MM> 3)  signif(100*probs,       max(3, .Options$digits - 3))
MM> 
MM> or then replace  "max(3, .Options$digits - 3)"
MM> by the new argument  'digits.names'
MM> and have that one default to
MM>         digits.names = max(3, .Options$digits - 3)

which should be corrected...
to something like

	formatC(100 * probs, dig= max(3, .Options$digits), wid=3)

[which is marginally better than Peter's solution...
 HOWEVER, when tested with funny .Options$digits,
 triggered a bug in formatC(.) ....  which I am going to fix now.....
]

- Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._