[R] How do I format something as "0.000"?
Achim Zeileis
Achim.Zeileis at wu-wien.ac.at
Mon Jan 17 17:03:36 CET 2005
On Mon, 17 Jan 2005 16:49:35 +0100 (MET) Christian Hennig wrote:
> Hi,
>
> I would like to use the format function to get numbers all with three
> digits to the right of the decimal point, even in cases where there is
> no significant digit left. For example, I would like to get
> c(0.3456789,0.0000053) as "0.346" "0.000".
> It seems that it is not possible to force format to print a "0.000",
> i.e. without any significant decimal places.
> Is it possible to do this somehow in R?
You can round() before:
R> x <- c(0.3456789,0.0000053)
R> round(x, digits = 3)
[1] 0.346 0.000
R> format(round(x, digits = 3))
[1] "0.346" "0.000"
hth,
Z
> Thanks,
> Christian
>
>
> *********************************************************************
> ** Christian Hennig
> Fachbereich Mathematik-SPST/ZMS, Universitaet Hamburg
> hennig at math.uni-hamburg.de,
> http://www.math.uni-hamburg.de/home/hennig/
> #####################################################################
> ###
> ich empfehle www.boag-online.de
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list