[R] alternatives to latex() or xtable() ?

Liviu Andronic landronimirc at gmail.com
Wed Dec 5 13:49:54 CET 2007


On 12/5/07, Romain Francois <rfrancois at mango-solutions.com> wrote:
>
>
>
> Hello,
>
>  My guess is that you are actually talking about the numSummary function in
> Rcmdr, not in abind. In that case, you can look how the structure of the
> output is like:
>
>  > str( numSummary( iris[,1:4] ) )
>  List of 4
>   $ type      : num 3
>   $ table     : num [1:4, 1:7] 5.843 3.057 3.758 1.199 0.828 ...
>    ..- attr(*, "dimnames")=List of 2
>    .. ..$ : chr [1:4] "Sepal.Length" "Sepal.Width" "Petal.Length"
> "Petal.Width"
>    .. ..$ : chr [1:7] "mean" "sd" "0%" "25%" ...
>   $ statistics: chr [1:3] "mean" "sd" "quantiles"
>   $ n         : Named num [1:4] 150 150 150 150
>    ..- attr(*, "names")= chr [1:4] "Sepal.Length" "Sepal.Width"
> "Petal.Length" "Petal.Width"
>   - attr(*, "class")= chr "numSummary"
>
>  and then use the table element from it:
>
>  > xtable( numSummary( iris[,1:4] )$table )
>  % latex table generated in R 2.6.0 by xtable 1.5-2 package
>  % Wed Dec 05 12:16:44 2007
>  \begin{table}[ht]
>  \begin{center}
>  \begin{tabular}{rrrrrrrr}
>    \hline
>   & mean & sd & 0\% & 25\% & 50\% & 75\% & 100\% \\
>    \hline
>  Sepal.Length & 5.84 & 0.83 & 4.30 & 5.10 & 5.80 & 6.40 & 7.90 \\
>    Sepal.Width & 3.06 & 0.44 & 2.00 & 2.80 & 3.00 & 3.30 & 4.40 \\
>    Petal.Length & 3.76 & 1.77 & 1.00 & 1.60 & 4.35 & 5.10 & 6.90 \\
>    Petal.Width & 1.20 & 0.76 & 0.10 & 0.30 & 1.30 & 1.80 & 2.50 \\
>     \hline
>  \end{tabular}
>  \end{center}
>  \end{table}
>
>  Otherwise, you can define your own xtable.numSummary function that would
> wrap this up. (This one does not do everything as it does not take into
> account the groups argument of numSummary, so you might want to do something
> else if you have used it, ...)
>
>  > xtable.numSummary <- function( x, ...){
>  +  out <- cbind( x$table, n = x$n )
>  +  xtable( out, ... )
>  + }
>  >  xtable( numSummary( iris[,1:4] ) )
>  % latex table generated in R 2.6.0 by xtable 1.5-2 package
>  % Wed Dec 05 12:20:13 2007
>  \begin{table}[ht]
>  \begin{center}
>  \begin{tabular}{rrrrrrrrr}
>    \hline
>   & mean & sd & 0\% & 25\% & 50\% & 75\% & 100\% & n \\
>    \hline
>  Sepal.Length & 5.84 & 0.83 & 4.30 & 5.10 & 5.80 & 6.40 & 7.90 & 150.00 \\
>    Sepal.Width & 3.06 & 0.44 & 2.00 & 2.80 & 3.00 & 3.30 & 4.40 & 150.00 \\
>    Petal.Length & 3.76 & 1.77 & 1.00 & 1.60 & 4.35 & 5.10 & 6.90 & 150.00 \\
>    Petal.Width & 1.20 & 0.76 & 0.10 & 0.30 & 1.30 & 1.80 & 2.50 & 150.00 \\
>     \hline
>  \end{tabular}
>  \end{center}
>  \end{table}
>
>  Hope this helps,
>  Romain

It helped. Thanks.
Liviu



More information about the R-help mailing list