[R] Export to LaTeX using xtable() - Control the digits to the right of the separator [solved]
Liviu Andronic
landronimirc at gmail.com
Wed Dec 5 14:42:49 CET 2007
Hello everyone,
The thread title speaks for itself. Here's the code that worked for me:
> numSummary(finance[,"Employees"], statistics=c("mean", "sd", "quantiles"))
mean sd 0% 25% 50% 75% 100% n NA
11492.92 29373.14 1777 3040 4267 6553 179774 53 5
> str(numSummary(finance[,"Employees"], statistics=c("mean", "sd", "quantiles")))
List of 5
$ type : num 3
$ table : num [1, 1:7] 11493 29373 1777 3040 4267 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr ""
.. ..$ : chr [1:7] "mean" "sd" "0%" "25%" ...
$ statistics: chr [1:3] "mean" "sd" "quantiles"
$ n : Named num 53
..- attr(*, "names")= chr "data"
$ NAs : Named num 5
..- attr(*, "names")= chr "data"
- attr(*, "class")= chr "numSummary"
> xtable(numSummary(finance[,"Employees"], statistics=c("mean", "sd", "quantiles"))$table, digit = c(0,0,2,2,2,0,0,0))
% latex table generated in R 2.6.1 by xtable 1.5-2 package
% Wed Dec 5 14:37:51 2007
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrrrrr}
\hline
& mean & sd & 0\% & 25\% & 50\% & 75\% & 100\% \\
\hline
1 & 11493 & 29373.14 & 1777.00 & 3040.00 & 4267 & 6553 & 179774 \\
\hline
\end{tabular}
\end{center}
\end{table}
Regards,
Liviu
---------- Forwarded message ----------
From: Romain Francois <rfrancois at mango-solutions.com>
Date: Dec 5, 2007 2:10 PM
Subject: RE: [R] alternatives to latex() or xtable() ?
To: Liviu Andronic <landronimirc at gmail.com>
You need to look at the digits argument of xtable that would allow you
to control this i think.
> xtable( numSummary( iris[,1:4] ) , digit = c( 0, 0, 2,2,2,2,2,2,0) )
% latex table generated in R 2.6.0 by xtable 1.5-2 package
% Wed Dec 05 13:07:47 2007
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrrrrrr}
\hline
& mean & sd & 0\% & 25\% & 50\% & 75\% & 100\% & n \\
\hline
Sepal.Length & 6 & 0.83 & 4.30 & 5.10 & 5.80 & 6.40 & 7.90 & 150 \\
Sepal.Width & 3 & 0.44 & 2.00 & 2.80 & 3.00 & 3.30 & 4.40 & 150 \\
Petal.Length & 4 & 1.77 & 1.00 & 1.60 & 4.35 & 5.10 & 6.90 & 150 \\
Petal.Width & 1 & 0.76 & 0.10 & 0.30 & 1.30 & 1.80 & 2.50 & 150 \\
\hline
\end{tabular}
\end{center}
\end{table}
-----Original Message-----
From: Liviu Andronic [mailto:landronimirc at gmail.com]
Sent: Wed 05/12/2007 13:07
To: Romain Francois
Subject: Re: [R] alternatives to latex() or xtable() ?
I have not yet understood how to set the number of displayed digits
after the period (not sure how to express correctly in English) in the
exported TeX code. For example, I would like to make all numbers
display as integers. Or, I would like to have 123.00 numbers display
as integers and the rest 123.212(3) display as 123.21. Do you know how
this is done within R? (I understand that I can perfectly do this
manually in the TeX code).
Thanks in advance,
Liviu
More information about the R-help
mailing list