Re: [R] format a number

2008-03-10 Thread jim holtman
Sorry, I missed the part about not having th leading zero. It is too early yet with daylight savings time and no coffee so far. On 3/10/08, Martin Kaffanke <[EMAIL PROTECTED]> 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(

Re: [R] format a number

2008-03-10 Thread jim holtman
You can also use sprintf: > v = c(0.43554, -0.22343) > sprintf("%.2f", v) [1] "0.44" "-0.22" > On 3/10/08, Martin Kaffanke <[EMAIL PROTECTED]> 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

Re: [R] format a number

2008-03-10 Thread Romain Francois
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, >

[R] format a number

2008-03-10 Thread Martin Kaffanke
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) Th