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
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.
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.
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.
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=",")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With