Re: [R] comma as decimal separator in xtable

2009-09-16 Thread Jakson A. Aquino
On Wed, Sep 16, 2009 at 03:16:12PM -0300, Henrique Dallazuanna wrote:
> Try this:
> 
> sapply(x, format, decimal.mark = ',')

Yes, this works as I need, regarding the replacement of dots with
commas.

Thanks!

> 
> On Wed, Sep 16, 2009 at 2:06 PM, Jakson A. Aquino
>  wrote:
> > 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"

__
R-help@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.


Re: [R] comma as decimal separator in xtable

2009-09-16 Thread Henrique Dallazuanna
Try this:

sapply(x, format, decimal.mark = ',')

On Wed, Sep 16, 2009 at 2:06 PM, Jakson A. Aquino
 wrote:
> 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.
>
> __
> R-help@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

__
R-help@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.


Re: [R] comma as decimal separator in xtable

2009-09-16 Thread Jakson A. Aquino

On Wed, Sep 16, 2009 at 03:29:44PM +0200, David Hajage wrote:
> But, it seems that dcolumn can change the decimal separator too (see the
> table on the first page of the pdf document).
> 
> For example:
> 
> \documentclass{article}
> 
> \usepackage{dcolumn}
> 
> \newcolumntype{d}[1]{D{.}{,}{#1}}
> 
> \begin{document}
> 
> <>=
> x <- matrix(rnorm(4), 2, 2)
> library(xtable)
> xtable(x, align = c("l", "|", "d{2}", "|", "c", "|"))
> @
> 
> \end{document}

It works. Thanks!

> 
> 2009/9/16 Jakson A. Aquino 
> 
> > On Wed, Sep 16, 2009 at 01:59:29PM +0200, David Hajage wrote:
> > > Perhaps with the dcolumn package ?
> > > http://newton.ex.ac.uk/research/qsystems/people/latham/LaTeX/dcolumn.pdf

__
R-help@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.


Re: [R] comma as decimal separator in xtable

2009-09-16 Thread Jakson A. Aquino
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.

__
R-help@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.


Re: [R] comma as decimal separator in xtable

2009-09-16 Thread David Hajage
But, it seems that dcolumn can change the decimal separator too (see the
table on the first page of the pdf document).

For example:

\documentclass{article}

\usepackage{dcolumn}

\newcolumntype{d}[1]{D{.}{,}{#1}}

\begin{document}

<>=
x <- matrix(rnorm(4), 2, 2)
library(xtable)
xtable(x, align = c("l", "|", "d{2}", "|", "c", "|"))
@

\end{document}

2009/9/16 Jakson A. Aquino 

> On Wed, Sep 16, 2009 at 01:59:29PM +0200, David Hajage wrote:
> > Perhaps with the dcolumn package ?
> > http://newton.ex.ac.uk/research/qsystems/people/latham/LaTeX/dcolumn.pdf
>
> Thanks for the suggestion, but the problem isn't of alignment.
> When I have commas as decimal separators, the values are
> aligned because all values of each column were formated with the
> same number of digits.
>
> __
> R-help@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@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.


Re: [R] comma as decimal separator in xtable

2009-09-16 Thread Jakson A. Aquino
On Wed, Sep 16, 2009 at 01:59:29PM +0200, David Hajage wrote:
> Perhaps with the dcolumn package ?
> http://newton.ex.ac.uk/research/qsystems/people/latham/LaTeX/dcolumn.pdf

Thanks for the suggestion, but the problem isn't of alignment.
When I have commas as decimal separators, the values are
aligned because all values of each column were formated with the
same number of digits.

__
R-help@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.


Re: [R] comma as decimal separator in xtable

2009-09-16 Thread Henrique Dallazuanna
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
 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 
>> 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@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@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@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

__
R-help@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.


Re: [R] comma as decimal separator in xtable

2009-09-16 Thread David Hajage
Perhaps with the dcolumn package ?
http://newton.ex.ac.uk/research/qsystems/people/latham/LaTeX/dcolumn.pdf

David

2009/9/16 Jakson A. Aquino 

> 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 <
> jaksonaqu...@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@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@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@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@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.


Re: [R] comma as decimal separator in xtable

2009-09-16 Thread Jakson A. Aquino
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 
> 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@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@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@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.


Re: [R] comma as decimal separator in xtable

2009-09-15 Thread Schalk Heunis
This might be of help, first applies the formatting:print(xtable(prettyNum(d,
decimal.mark=",")))



Schalk Heunis


On Tue, Sep 15, 2009 at 5:06 PM, Jakson A. Aquino 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@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@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] comma as decimal separator in xtable

2009-09-15 Thread Jakson A. Aquino
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@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.