Package for formatting numerical values ​​in reproducible studies

Is there a standard way to convert numeric values ​​to a character with a specific type of formatting.

I am thinking of something like:

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

Obviously, it’s not so difficult to write them yourself, but the need for such things is quite constant when preparing reports, and should there already be some kind of package?

+6
source share
1 answer

The scales package provides several 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" 
+9
source

Source: https://habr.com/ru/post/944903/


All Articles