[R] comma as decimal separator in xtable

Jakson A. Aquino jaksonaquino at gmail.com
Wed Sep 16 19:06:42 CEST 2009


On Wed, Sep 16, 2009 at 09:14:39AM -0300, Henrique Dallazuanna wrote:
> Try this also;
> 
> format(coef(summary(lm.D9)), decimal.mark = ',')
> 
> or using gsub:
> 
>  apply(coef(summary(lm.D9)), 2, gsub, pattern = "\\.", replacement = ",")
> 
> using lm.D9 object from ?lm example.

Thanks for your suggestion! The problem with the above approach is
that all values get the same formatting. For example, 

x <- c(1.2, 1.2e10)
format(x, format = 'g', decimal.mark = ',')
[1] "1,2e+00" "1,2e+10"

What I would like to get was:
[1] "1,2" "1,2e+10"

I already solved my problem, but I'm using an external program to
replace "." with ",". Perhaps I should ask my question again, with a
new subject, since what I need now is the perl regular expression
equivalent to the sed command:

s/\([0-9]\)a/a\1/

That's is, "1a" becomes "a1"; "3b" becomes "b3", etc.




More information about the R-help mailing list