Printing a data.table
adds a number for each line of output before the actual output, e.g.
> DT <- data.table(cbind(1:3,3:1))
> DT
V1 V2
1: 1 3
2: 2 2
3: 3 1
> print(DT)
V1 V2
1: 1 3
2: 2 2
3: 3 1
How can I avoid printing the "1:", "2:", "3:" before the data rows? I would like write html- or latex-formated output of my data using xtable
.
print.data.table
has an argument row.names
, which is set to TRUE by default. Just use
> print(DT, row.names=FALSE)
V1 V2
1 3
2 2
3 1
If you want to supress the names in xtable()
output, you need to use
the arguments to print.xtable()
:
library(xtable)
df <- data.frame(x = 1:3, y = 3:1)
xtable(df)
## % latex table generated in R 3.0.2 by xtable 1.7-1 package
## % Wed Apr 9 06:53:55 2014
## \begin{table}[ht]
## \centering
## \begin{tabular}{rrr}
## \hline
## & x & y \\
## \hline
## 1 & 1 & 3 \\
## 2 & 2 & 2 \\
## 3 & 3 & 1 \\
## \hline
## \end{tabular}
## \end{table}
print(xtable(df), include.rownames = FALSE)
## % latex table generated in R 3.0.2 by xtable 1.7-1 package
## % Wed Apr 9 06:53:55 2014
## \begin{table}[ht]
## \centering
## \begin{tabular}{rr}
## \hline
## x & y \\
## \hline
## 1 & 3 \\
## 2 & 2 \\
## 3 & 1 \\
## \hline
## \end{tabular}
## \end{table}
In this case it doesn't matter that you're using a data.table instead of a data.frame
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With