Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package for formatting numeric values in reproducible research

Is there a standard way of converting numeric values to character with a particular type of formatting applied.

I'm thinking of something like:

formatR(32390,"dollars")
# returns "$32,390"
formatR(1.25,"percent")
# returns "125%"

Obviously, not so hard to write them myself, but the need for this kind of thing is pretty constant in when preparing reports, and there must be some package out there already?

like image 300
Ari B. Friedman Avatar asked May 13 '13 17:05

Ari B. Friedman


1 Answers

The scales package provides a few formatting functions,

> scales::percent(c(1.2, 0.13))
[1] "120%" "13%" 
> scales::dollar(c(1.2, 0.13))
[1] "$1.20" "$0.13"
> scales::comma(c(1.2, 0.13))
[1] "1.20" "0.13"
> scales::comma(scales::dollar(6000.88))
[1] "$6,000.88"
like image 129
baptiste Avatar answered Oct 31 '22 11:10

baptiste