[R] format numbers into percentages
Henrik Bengtsson
hb at stat.berkeley.edu
Sun Mar 9 23:58:09 CET 2008
On Sun, Mar 9, 2008 at 3:36 PM, tom soyer <tom.soyer at gmail.com> wrote:
> Hi,
>
> I am currently using the following to formate numbers into percentages:
>
> x=0.00112
> paste(round(x*100,2),"%",sep="")
My favorite is sprintf(), which allow you to control number of digits
at the same time you control for width etc, e.g.:
x <- seq(from=0, to=1, by=0.05)
s1 <- sprintf("%.2f%%", 100*x)
s2 <- sprintf("%6.2f%%", 100*x)
/H
>
> I am wondering if there is a built in R function that does the same. Does
> anyone know?
>
> Thanks,
>
> --
> Tom
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list