format01prec {DPQ}R Documentation

Format Numbers in [0,1] with "Precise" Result

Description

Format numbers in [0,1] with “precise” result, notably using "1-.." if needed.

Usage

format01prec(x, digits = getOption("digits"), width = digits + 2,
             eps = 1e-06, ...,
             FUN = function(x, ...) formatC(x, flag = "-", ...))

Arguments

x

numbers in [0,1]; (still works if not)

digits

number of digits to use; is used as FUN(*, digits = digits) or FUN(*, digits = digits - 5) depending on x or eps.

width

desired width (of strings in characters), is used as FUN(*, width = width) or FUN(*, width = width - 2) depending on x or eps.

eps

small positive number: Use '1-' for those x which are in (1-eps, 1]. The author has claimed in the last millennium that (the default) 1e-6 is optimal.

...

optional further arguments passed to FUN(x, digits, width, ...).

FUN

a function used for format()ing; must accept both a digits and width argument.

Value

a character vector of the same length as x.

Author(s)

Martin Maechler, 14 May 1997

See Also

formatC, format.pval.

Examples

## Show that format01prec()  does reveal more precision :
cbind(format      (1 - 2^-(16:24)),
      format01prec(1 - 2^-(16:24)))

## a bit more variety
e <- c(2^seq(-24,0, by=2), 10^-(7:1))
ee <- sort(unique(c(e, 1-e)))
noquote(ff <- format01prec(ee))
data.frame(ee, format01prec = ff)

[Package DPQ version 0.5-8 Index]