Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add commas into number for output

Tags:

r

xtable

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.

like image 308
Dan Avatar asked Oct 17 '09 02:10

Dan


People also ask

How do you add a comma to output in Python?

In Python, to format a number with commas we will use “{:,}” along with the format() function and it will add a comma to every thousand places starting from left. After writing the above code (python format number with commas), Ones you will print “numbers” then the output will appear as a “ 5,000,000”.

How do you add commas to numbers in Excel?

We can use accounting Excel format in the “Number” format ribbon, select the amount cell, click on ribbon home, and select the “Comma Style” from the “Number” format column. Once we click on the “Comma Style,” it will provide the comma-separated format value.


1 Answers

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" 
like image 200
Jonathan Chang Avatar answered Nov 05 '22 06:11

Jonathan Chang