I can change the decimal character from output using:
> 1/2
[1] 0.5
> options(OutDec = ',')
> 1/2
[1] 0,5
But, this change does not affect sprintf()
function.
> sprintf('%.1f', 1/2)
[1] "0.5"
So, my question is: There is an easy way to change it (the decimal character)? I think that I can't use a 'simple' RE because not every .
need be traded by ,
.
I don't have any idea of how to do it, so I can't say what I've already done.
I think you can do this by setting your locale appropriately, making sure that the LC_NUMERIC
component is set to a locale that uses a comma as the decimal separator (http://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html).
Sys.setlocale("LC_NUMERIC","es_ES.utf8")
sprintf("%f",1.5)
## "1,500000"
This gives a warning that R may behave strangely; you probably want to switch LC_NUMERIC
back to C as soon as you're done generating output.
Try this
sprintf("%s",format(1.5,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