Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In R print decimal comma instead of decimal point

Tags:

r

I am doing statistical analysis in R. I need to paste the results in a report written in French. In French, floating point numbers are written using a decimal comma instead of decimal point.

Manually replacing points by commas is a bit tedious...

1/ How may I have R print all my floating point numbers with a comma separating the integer and decimal parts ?

Many thanks to rmuc8 for having answered very quickly and effectively to this first question:

options(OutDec= ",")

This will yield e.g.

3.14

[1] 3,14

2/ How may I have R's sprintf("%.1f", x) doing the same ? e.g I'd like

sprintf("%.2f", 3.14)

to give the character string

[1] "3,14"

instead of

[1] "3.14"

Many thanks in advance for any help

like image 406
Mô Dang Avatar asked Mar 27 '15 11:03

Mô Dang


People also ask

Can you use a comma instead of a decimal point?

A decimal marker (i.e. a decimal separator, decimal sign, or radix character/point) is a symbol used to separate the integer and fractional parts of a number. In 2.3, 2 is the integer (i.e. whole number) and 3 is the fractional part. A decimal marker can be either a period or a comma.

How do I fix decimal places in R?

To format all decimal places in an R vector and data frame, we can use formattable function of formattable package where we can specify the number of digits after decimal places.

How do you use a comma with decimals?

And in countries where a point is used as a decimal separator, a comma is usually used to separate thousands. So, for example, twelve thousand five hundred with a decimal of five zero is written differently depending on the country: In the USA, Mexico, or the UK, it would be written: 12 500.50 or 12,500.50.


1 Answers

Try it with options

options(OutDec= ",")

If you want to apply it on an object like a data.frame, you can use format

format(name_of_dataframe, decimal.mark=",")
like image 90
rmuc8 Avatar answered Nov 15 '22 05:11

rmuc8