I've got a CSV file that looks like this:
RTT,From,Req,Bytes,TTL
202,10.0.0.10,1,64,64
191,10.0.0.10,2,64,64
...
I am trying to produce a LaTeX summary()
using library(xtable)
, like so:
library(xtable)
pings <- read.csv("pings.csv")
s <- summary(pings$RTT)
xtable(t(s))
This produces the output:
\begin{table}[ht]
\centering
\begin{tabular}{rrrrrrr}
\hline
& Min. & 1st Qu. & Median & Mean & 3rd Qu. & Max. \\
\hline
1 & 40.70 & 42.70 & 43.40 & 44.90 & 44.10 & 202.00 \\
\hline
\end{tabular}
\end{table}
This is almost what I want, except for the first column containing an empty value and 1
.
Clearly, I'm missing some vital, basic knowledge about data types and conversions in R. The problem is of course that t(s)
produces:
Min. 1st Qu. Median Mean 3rd Qu. Max.
[1,] 40.7 42.7 43.4 44.9 44.1 202.0
wherein the [,1]
should explain xtable's output.
Can anyone please point out to me what I'm doing wrong?
If I'm simply trying to run xtable on the summary, I get
> xtable(summary(pings$RTT))
Error in xtable.table(summary(pings$RTT)) :
xtable.table is not implemented for tables of > 2 dimensions
This is handled by print.xtable()
:
> library(xtable)
> print.xtable(xtable(t(summary(runif(10)))), include.rownames=FALSE)
% latex table generated in R 3.0.2 by xtable 1.7-3 package
% Sat Apr 26 20:03:32 2014
\begin{table}[ht]
\centering
\begin{tabular}{rrrrrr}
\hline
Min. & 1st Qu. & Median & Mean & 3rd Qu. & Max. \\
\hline
0.03 & 0.18 & 0.48 & 0.41 & 0.61 & 0.74 \\
\hline
\end{tabular}
\end{table}
Here include.rownames=FALSE
disables outputting row names. See ?print.xtable
for more details.