[R] comma as decimal separator in xtable

Henrique Dallazuanna wwwhsd at gmail.com
Wed Sep 16 14:14:39 CEST 2009


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.

On Wed, Sep 16, 2009 at 8:50 AM, Jakson A. Aquino
<jaksonaquino at gmail.com> wrote:
> On Wed, Sep 16, 2009 at 07:11:46AM +0200, Schalk Heunis wrote:
>> This might be of help, first applies the formatting:print(xtable(prettyNum(d,
>> decimal.mark=",")))
>
> Thanks! Your solution works for the example that I gave.
> However, I failed to provide an example that really represent my
> problem because I'm passing a lm object to xtable.
>
> Currently, I'm using the following function, which also puts the
> table header in bold font:
>
> tabprint <- function(x, ...) {
>  colsani <- function(x){paste("{\\bf ", x, "}", sep = "")}
>  p <- capture.output(print(x, caption.placement = "top",
>        sanitize.colnames.function = colsani, ...))
>  writeLines(p, "/tmp/xtableOutPut")
>  system("sed -i -e 's/\\([0-9]\\)\\.\\([0-9]\\)/\\1,\\2/g' /tmp/xtableOutPut")
>  p <- readLines("/tmp/xtableOutPut")
>  cat(p, sep = "\n")
> }
>
> tabprint(xtable(lm.model))
>
> I could call gsub() if I knew the perl regular expression
> equivalent to the sed one that I'm using.
>
>
>> On Tue, Sep 15, 2009 at 5:06 PM, Jakson A. Aquino <jaksonaquino at gmail.com>wrote:
>>
>> > Hello,
>> >
>> > How can I make xtable print a comma as decimal separator? Setting
>> > the option OutDec isn't enough for xtable:
>> >
>> > library(xtable)
>> > options(OutDec = ",")
>> >
>> > x <- c(1.1, 1.2, 1.3)
>> > y <- c(2.3, 2.2, 2.1)
>> > d <- data.frame(x, y)
>> >
>> > d
>> > print(xtable(d))
>> >
>> >
>> > Thanks!
>> >
>> > Jakson Aquino
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list