Format numbers to significant figures nicely in R

Sorry I never updated this at the time. None of the statements in my question, or prettynum worked. In the end I used

print(formatC(signif(numbers[n],digits=3), digits=3,format="fg", flag="#"))

which correctly coped with trailing zero's and big numbers.


Are you aware of prettyNum() and all its options?


A more barebones option is options(), which just does rounding. If you plan on doing this a lot, I suggest checking out Sweave.

> a <- 1.23456789
> options(digits=2)
> a
[1] 1.2
> options(digits=6)
> a
[1] 1.23457

If you like scientific notation

> format(2^31-1, scientific = TRUE, digits = 3)
[1] "2.15e+09"