add commas into number for output

Dan picture Dan · Oct 17, 2009 · Viewed 39.6k times · Source

I'm outputting a dataframe to html via xtable. I want to add commas to numbers in a couple columns of the table. I figured before I did my own paste hack I'd check if there is a built in way to do this.

Answer

Jonathan Chang picture Jonathan Chang · Oct 17, 2009

You might want to consider transforming the column using formatC

> formatC(1:10 * 100000, format="d", big.mark=",")
 [1] "100,000"   "200,000"   "300,000"   "400,000"   "500,000"   "600,000"  
 [7] "700,000"   "800,000"   "900,000"   "1,000,000"