Skip to content
Prev 70658 / 398525 Next

Formatting numbers with a limited amount of digits consistently

Henrik Andersson wrote:
signif() changes the value; you don't want that, you want to affect how 
a number is displayed.  Use format() or formatC() instead, for example

 > x <- c(17.01, 18.15)
 > format(x, digits=3)
[1] "17.0" "18.1"
 > noquote(format(x, digits=3))
[1] 17.0 18.1
I'd say both.

Duncan Murdoch