Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xtable in R: Cannot get rid of row numbers [duplicate]

I have a dataframe in R that I create like this:

estimate1 = rep(1,times=4)
standardError = rep(2, times = 4)
pvalue = runif(4, min=0, max=1)
rowNames =c('Thing1','Things2','Thing3','Thing4')
tableResults = as.data.frame(cbind(rowNames, estimate1, standardError, pvalue))

When I try to write to a text file using:

xtable(tableResults, include.rownames=FALSE) 

I get:

\begin{tabular}{rllll}
  \hline
 & rowNames & estimate1 & standardError & pvalue \\ 
  \hline
  1 & Thing1 & 1 & 2 & 0.624112528283149 \\ 
  2 & Things2 & 1 & 2 & 0.516147756483406 \\ 
  3 & Thing3 & 1 & 2 & 0.756535144057125 \\ 
  4 & Thing4 & 1 & 2 & 0.0105485401581973 \\ 
   \hline
\end{tabular}

I can't figure out how to get rid of the row numbers in the first column. I thought the "include.rownames=FALSE" would get rid of it, but that doesn't work.

like image 306
Eli Avatar asked Jul 06 '16 15:07

Eli


People also ask

How do I remove row names in R?

Method 2: Assigning row names to NULL In case, the row names are explicitly assigned to the rows, then using rownames(df) to NULL, deletes the row names and uses row numbers to access the rows.

How do I drop an index in a Dataframe in R?

The most easiest way to drop columns is by using subset() function. In the code below, we are telling R to drop variables x and z. The '-' sign indicates dropping variables. Make sure the variable names would NOT be specified in quotes when using subset() function.

What does row names false do in R?

The default (is back compatible), FALSE , will signal an error, where NA will “automatic” row names and TRUE will call make. names(value, unique=TRUE) for constructing valid names. an object to be coerced to character unless an integer vector.


1 Answers

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}
like image 158
lmo Avatar answered Sep 28 '22 05:09

lmo