Here are a few ways to format numbers in R for presentations. A few of theme can be accomplished using the paste function in R. I’ve found that there are a few different methods to do this.
Using the scales package
Using the scales packages from Hadley, there is a great function with various options including passing a vector.
library(scales)
dollar_format()(c(-100, 0.23, 1.456565, 2e3))
Formatting currency with separator
Following is a simple function one can build and place in their utility function that will give formatted currency.
myNum = 1234.12
toCurrency <- function(money)
{
paste("$",format(money, big.mark=","),sep="")
}
toCurrency(myNum)