[R] Problem using xtable on an array
Uwe Ligges
ligges at statistik.uni-dortmund.de
Thu Sep 13 10:54:00 CEST 2007
Peter Dunn wrote:
> Hi all
>
> I know about producing a minimal example to show my problem. But I'm
> having trouble producing a minimal example that displays this
> behaviour, so please bear with me to begin with.
>
>
> Observe: I create an array called model.mat. Some details on this:
>
>> str(model.mat)
> num [1:18, 1:4] -0.170 -0.304 -2.617 2.025 -1.610 ...
> - attr(*, "dimnames")=List of 2
> ..$ : chr [1:18] "Amount: CP for VF" "Amount: CP for F" "Amount: CP for
> M" "Amount: RD for VF" ...
> ..$ : chr [1:4] "beta_0" "P-value" "beta_1" "P-value"
>
>
> It contains the following:
>
>> model.mat[1:2,]
> beta_0 P-value beta_1 P-value
> Amount: CP for VF -0.1702877 0.7716153 0.5148616 2.020602e-03
> Amount: CP for F -0.3042522 0.1966133 0.8795982 6.058299e-12
>
>
>
> That's fine. Now to produce a LaTeX table using xtable,
> I get:
>
>> xtable(model.mat[1:2,])
> <snip>
> Amount: CP for VF & $-$0.17 & 0.77 & 0.51 & 0.77 \\
> Amount: CP for F & $-$0.30 & 0.20 & 0.88 & 0.20 \\
> <snip>
>
> That is, the final column does *not* correspond to the final
> column of model.mat itself. It is actually column 2 repeated.
>
> What's going on? If I try repeating on a minimal type example,
> xtable works as expected:
>
>
>> fred <- array( seq(1,18*4), dim=c(18,4))
>> fred[1:2, ]
> [,1] [,2] [,3] [,4]
> [1,] 1 19 37 55
> [2,] 2 20 38 56
>> xtable(fred[1:2, ])
> % latex table generated in R 2.5.0 by xtable 1.4-6 package
> % Thu Sep 13 14:09:46 2007
> \begin{table}[ht]
> \begin{center}
> \begin{tabular}{rrrrr}
> \hline
> & 1 & 2 & 3 & 4 \\
> \hline
> 1 & 1 & 19 & 37 & 55 \\
> 2 & 2 & 20 & 38 & 56 \\
> \hline
> \end{tabular}
> \end{center}
> \end{table}
>
>
> So it is not a generic problem. But what could it be? I can't decide
> where to look, so find a solution or produce a minimal example to display
> this behaviour. I actually use this construct with xtable a lot, so
> it disturbs me to find this error... which is probably is something
> I am doing.
>
>
>
> The problem exists for a smaller subsets of this array also; let's take
> columns 2, 3 and 4 only:
>
>> model.mat[1:2,2:4]
> P-value beta_1 P-value
> Amount: CP for VF 0.7716153 0.5148616 2.020602e-03
> Amount: CP for F 0.1966133 0.8795982 6.058299e-12
>> xtable(model.mat[1:2,2:4])
> % latex table generated in R 2.5.0 by xtable 1.4-6 package
> % Thu Sep 13 14:04:40 2007
> \begin{table}[ht]
> \begin{center}
> \begin{tabular}{rrrr}
> \hline
> & P-value & beta\_1 & P-value \\
> \hline
> Amount: CP for VF & 0.77 & 0.51 & 0.77 \\
> Amount: CP for F & 0.20 & 0.88 & 0.20 \\
> \hline
> \end{tabular}
> \end{center}
> \end{table}
>
>
> Is it a problem with my particular array model.mat or something
> I am doing wrong/silly? I don't know where to start.
>
> Thanks all, as always.
>
> P.
>
>> sessionInfo()
> R version 2.5.0 (2007-04-23)
> i486-pc-linux-gnu
>
> locale:
> LC_CTYPE=en_AU.UTF-8;LC_NUMERIC=C;LC_TIME=en_AU.UTF-8;LC_COLLATE=en_AU.UTF-8;LC_MONETARY=en_AU.UTF-8;LC_MESSAGES=en_AU.UTF-8;LC_PAPER=en_AU.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_AU.UTF-8;LC_IDENTIFICATION=C
>
> attached base packages:
> [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
> [7] "base"
>
> other attached packages:
> car xtable statmod
> "1.2-1" "1.4-6" "1.3.0"
1. a) Please start by upgrading R to at least teh current release
R-2.5.1 or even better the current R-alpha version where you could help
testing.
1. b) Please upgrade you version of xtable. Current release is 1.5-1.
2. If the problem is still there, please send the model.mat[1:2,2:4]
object (by e.g. using save()) to the package maintainer of xtable and
report the problem. I am CCing now already.
Best,
Uwe Ligges
>
>
More information about the R-help
mailing list