Re: [R] Format with n significant figures / digits

2008-08-19 Thread wannymahoots
In case anyone has the same problem and wants a solution, here is mine (albeit with some horrible hacks): "my.signif" <- function(vec, digits=6) { # get correct number of significant figures vec = signif(vec, digits) # now get correct number of trailing zeros by calling sprintf and sp

Re: [R] Format with n significant figures / digits

2008-08-14 Thread wannymahoots
I am not sure that format solves the problem (although again I may well be missing something) # trailing zeros on large numbers >format(vec, digits=4, scientific=F) [1] " 0.8000" "123.4567" " 0.1235" " 7.6543" "7654321." # misses trailing zeros > format(vec[1], digits

[R] Format with n significant figures / digits

2008-08-14 Thread wannymahoots
Hi everyone, I can't figure out how to format numbers to have a certain number of significant figures (as opposed to decimal places) without using scientific notation and including trailing zeros if necessary. e.g. I would like to achieve the following: 0.81 ---> 0.8000 123.4567--