6

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

Community
  • 1
  • 1
Mô Dang
  • 63
  • 1
  • 4

1 Answers1

8

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=",")
rmuc8
  • 2,869
  • 7
  • 27
  • 36