[R] format a number

Romain Francois rfrancois at mango-solutions.com
Mon Mar 10 12:20:31 CET 2008


Hello,

 > sub( "^([- ])?0+", "\\1", format(v, digits=2) )
[1] " .44" "-.22"

Cheers,

Romain


Martin Kaffanke wrote:
> Hi there!
>
> I have i.e. v = c(0.43554, -0.22343), and so on.  Now I'd like to make a
> format like
>
> format(v, digits=2)  but without the leading 0, so 0.43554 becomes .44,
> -0.22343 becomes -.22 
>
> How can I do that?
>
> runnable example for copy and paste:
>
> v = c(0.43554, -0.22343)
> format(v, digits=2)
>
> Thanks,
> Martin
-- 

Mango Solutions
data analysis that delivers

Tel:  +44(0) 1249 76 77 00
Fax:  +44(0) 1249 76 77 07
Mob:  +44(0) 7813 52 61 23



More information about the R-help mailing list