Re: [R] Displaying trailing zeroes
formatC(round(12.01), digits=1, format=f) -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Lucke, Joseph F Sent: Thursday, January 24, 2008 4:37 PM To: r-help@r-project.org Subject: [R] Displaying trailing zeroes round(12.01,1) will give the answer 12, not 12.0 or even 12. To make a table look nice, I need to display the trailing zero so that just as round(12.05,1) yields 12.1, round(12.01) yields 12.0. I cannot find an answer in print() or format() or options(). Any suggestions would be appreciated. Joseph F. Lucke, PhD Biostatistician Center for Clinical Research and Evidence-based Medicine University of Texas Medical School at Houston Email: [EMAIL PROTECTED] __ R-help@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. __ R-help@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.
Re: [R] Displaying trailing zeroes
On 24/01/2008 4:36 PM, Lucke, Joseph F wrote: round(12.01,1) will give the answer 12, not 12.0 or even 12. Those are all the same number. You aren't asking about the answer, you are asking about how to control how the number is printed. To make a table look nice, I need to display the trailing zero so that just as round(12.05,1) yields 12.1, round(12.01) yields 12.0. I cannot find an answer in print() or format() or options(). Any suggestions would be appreciated. R tries to be consistent when it prints a vector, so you could convert all the entries at once. For example, x - c(12, 12.1) format(x) [1] 12.0 12.1 If you want individual control on each entry, see formatC or sprintf. Christos gave you the formatC version; the sprintf version is sprintf(%.1f, 12) [1] 12.0 Duncan Murdoch Joseph F. Lucke, PhD Biostatistician Center for Clinical Research and Evidence-based Medicine University of Texas Medical School at Houston Email: [EMAIL PROTECTED] __ R-help@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. __ R-help@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.
Re: [R] Displaying trailing zeroes
Lucke, Joseph F wrote: round(12.01,1) will give the answer 12, not 12.0 or even 12. To make a table look nice, I need to display the trailing zero so that just as round(12.05,1) yields 12.1, round(12.01) yields 12.0. I cannot find an answer in print() or format() or options(). Any suggestions would be appreciated. formatC(round(12.01,1),1,format=f) [1] 12.0 cat(sprintf(%6.1f\n, round(12.01,1))) 12.0 -- O__ Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@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.