3

In xtable, is there any way to print a latex table without rownames, but while keeping & on the left hand side?

I also don't want to set the rownames to NA in my data matrix to achieve this feat.

Example:

require(xtable)
o <- do.call(cbind,lapply(1:10,function(i) matrix(rnorm(10)) ))
print(xtable(o))

We can see on the LHS of this output, there's 1,2,3,4,...,10. This is bad. I don't want this.

However

print(xtable(o),include.rownames=FALSE)

doesn't give me what I want because it deletes the & at the LHS of the matrix.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jase
  • 1,025
  • 1
  • 9
  • 34
  • Shoot missed the keeping & on the left side. This isn't a duplicate. – Tyler Rinker Oct 07 '12 at 06:23
  • Check out two arguments: `include.rownames=FALSE` and `add.to.row` – Tyler Rinker Oct 07 '12 at 07:11
  • It would be helpful if you provided some data - what you have and how you want it to look like afterwards. From [your other post](http://stackoverflow.com/questions/12766173/xtable-package-skipping-some-rows-in-the-output) it seems you have a .txt file with the row names - why don't you import these row names into your R dataframe or matrix? – vaettchen Oct 07 '12 at 07:16
  • That's much harder and less time efficient than what I'm already doing, and very confusing for my co-author. I will add an example here. – Jase Oct 07 '12 at 07:18
  • @TylerRinker Funny, I can't get the first row to be affected by `add.to.row`. – Roman Luštrik Oct 07 '12 at 08:21
  • I guess what @Roman Luštrik was trying is to insert `&` via `add.to.row` - I did as well. However, there are three major problems: – vaettchen Oct 07 '12 at 09:10
  • This isn't a duplicate ... I want to keep the `&`. – Jase Oct 13 '12 at 13:23

1 Answers1

8

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!

Community
  • 1
  • 1
vaettchen
  • 7,299
  • 22
  • 41
  • Thank you! Where did you learn how to layout your code. E.g. `print( xtable( o )` with the spaces. – Jase Oct 07 '12 at 10:05
  • 1
    About 20 yrs ago, I did some `C`, and the book I used taught me that style. I like it because it is easily readable, but then, I'm just an amateur... – vaettchen Oct 07 '12 at 10:23
  • @Harokitty try searching for "R code style guide". A while ago I tried http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html and adapted a few things for my needs (and my IDE). – Roman Luštrik Oct 08 '12 at 07:03