[R] Displaying trailing zeroes

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Jan 24 23:29:20 CET 2008


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
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list