Remove data.frame row names when using xtable
Use include.rownames=FALSE
in the print
method.
See ?print.xtable
:
R> print(xtable(res), include.rownames=FALSE)
% latex table generated in R 2.12.2 by xtable 1.5-6 package
% Fri Mar 25 10:06:08 2011
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrr}
\hline
am & cyl & mpg & hp & wt \\
\hline
0.00 & 4.00 & 22.90 & 84.67 & 2.94 \\
0.00 & 6.00 & 19.12 & 115.25 & 3.39 \\
0.00 & 8.00 & 15.05 & 194.17 & 4.10 \\
1.00 & 4.00 & 28.07 & 81.88 & 2.04 \\
1.00 & 6.00 & 20.57 & 131.67 & 2.75 \\
1.00 & 8.00 & 15.40 & 299.50 & 3.37 \\
\hline
\end{tabular}
\end{center}
\end{table}
xtable in R: Cannot get rid of row numbers
include.rownames
is an argument for the print function of xtable
objects, print.xtable
, not the xtable
function. Use the following code instead:
print(xtable(tableResults), include.rownames=FALSE)
% latex table generated in R 3.2.3 by xtable 1.8-2 package
% Wed Jul 06 11:56:20 2016
\begin{table}[ht]
\centering
\begin{tabular}{llll}
\hline
rowNames & estimate1 & standardError & pvalue \\
\hline
Thing1 & 1 & 2 & 0.405261459294707 \\
Things2 & 1 & 2 & 0.611535826232284 \\
Thing3 & 1 & 2 & 0.482713349396363 \\
Thing4 & 1 & 2 & 0.242787319235504 \\
\hline
\end{tabular}
\end{table}
Removing rownames but keeping &
This builds on my response to your other post.
I could not resolve the problem of the first row as pointed out by @Roman Luštrik (sorry the editing time limit threw me out of my comment) but it should, according to my understanding, take care of both your problems after manually inserting the first &
:
o <- matrix( rnorm( 770, 10 ), ncol=10 )
addtorow <- list()
addtorow$pos <- list()
addtorow$pos[[1]] <- c(0:13,15:28,30:58,60:76)
addtorow$pos[[2]] <- c(14,29,59)
addtorow$command <- c( "&", "\\\\ \n &" )
print( xtable( o ), add.to.row = addtorow, include.rownames=FALSE )
Hope this makes your life (and that of your co-author) easier!
Removing display of row names from data frame
You have successfully removed the row names. The print.data.frame
method just shows the row numbers if no row names are present.
df1 <- data.frame(values = rnorm(3), group = letters[1:3],
row.names = paste0("RowName", 1:3))
print(df1)
# values group
#RowName1 -1.469809 a
#RowName2 -1.164943 b
#RowName3 0.899430 c
rownames(df1) <- NULL
print(df1)
# values group
#1 -1.469809 a
#2 -1.164943 b
#3 0.899430 c
You can suppress printing the row names and numbers in print.data.frame
with the argument row.names
as FALSE
.
print(df1, row.names = FALSE)
# values group
# -1.4345829 d
# 0.2182768 e
# -0.2855440 f
Edit: As written in the comments, you want to convert this to HTML. From the xtable
and print.xtable
documentation, you can see that the argument include.rownames
will do the trick.
library("xtable")
print(xtable(df1), type="html", include.rownames = FALSE)
#<!-- html table generated in R 3.1.0 by xtable 1.7-3 package -->
#<!-- Thu Jun 26 12:50:17 2014 -->
#<TABLE border=1>
#<TR> <TH> values </TH> <TH> group </TH> </TR>
#<TR> <TD align="right"> -0.34 </TD> <TD> a </TD> </TR>
#<TR> <TD align="right"> -1.04 </TD> <TD> b </TD> </TR>
#<TR> <TD align="right"> -0.48 </TD> <TD> c </TD> </TR>
#</TABLE>
remove row names from sf dataframe
Set rownames to NULL
You can use this code to remove row names from a data.frame
:
rownames(binded) <- NULL
Hope this helps.
Turn Off Row Names when Printing a Table
Try this:
grid.table(d, rows = NULL)
Related Topics
Can't Load X11 in R After Os X Yosemite Upgrade
Simple Frequency Tables Using Data.Table
Encrypting R Script Under Ms-Windows
Faster Way to Subset on Rows of a Data Frame in R
Multiple Functions in a Single Tapply or Aggregate Statement
What Does the Double Percentage Sign (%%) Mean
R Remove Non-Alphanumeric Symbols from a String
How to Plot Ellipse Given a General Equation in R
Auto Complete and Selection of Multiple Values in Text Box Shiny
Reorder Rows Using Custom Order
Remove Empty Elements from List with Character(0)
Barplot with 2 Variables Side by Side
Predicted Values for Logistic Regression from Glm and Stat_Smooth in Ggplot2 Are Different
Summarise_At Using Different Functions for Different Variables