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 -- Ihr Partner f?r Webdesign, Webapplikationen und Webspace. http://www.roomandspace.com/ Martin Kaffanke +43 650 4514224 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Dies ist ein digital signierter Nachrichtenteil Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080310/551887ca/attachment.bin
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
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 <technik at roomandspace.com> 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 > > -- > Ihr Partner f?r Webdesign, Webapplikationen und Webspace. > http://www.roomandspace.com/ > Martin Kaffanke +43 650 4514224 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
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 <technik at roomandspace.com> 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 > > -- > Ihr Partner f?r Webdesign, Webapplikationen und Webspace. > http://www.roomandspace.com/ > Martin Kaffanke +43 650 4514224 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?