signif2 | R Documentation |
Even if theoretically correct, the built-in 'R' functions 'round' and 'signif' can be confusing (see examples). 'signif2' is a simple solution that can be used for reporting results consistently.
signif2(x, digits = 1, add, ...)
x |
a numeric vector. |
digits |
number of significant digits to round to. Must be an integer larger than 0. |
add |
pad with zeros where digits>nchar(x[i]). Currently not used. |
... |
additional arguments passed to formatC. |
A character vector.
x <- c(1.24e-4,1.1334e6,1.1,22.00000,10.00,1)
data.frame(x,s.3=signif(x,3),sc.3=as.character(signif(x,3)),s2.3=signif2(x,3))
signif2(c(.2,11.84),2)
## digits has no effect when x==0
signif2(0,1)
signif2(0,3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.