问题
In the xtable
output, if I want some rows to have nothing in them I will put NA
's in the elements of the matrix that correspond to the row that I want skipped.
However this will lead to xtable output of something like & & & & & & & & \\
. What I want to know is how do I make it so it's ONLY \\
for that row that I wish to skip.
回答1:
Still not sure whether I understand right but I give it a shot.
The most important assumption I'm making here is that your multicolumn rows in that template are always at the same spot. You use R to create a matrix or dataframe with no (useful) data in these rows.
For the purpose of this example, the multicolumn rows are 15, 30 and 60 of a dataframe of 80 rows, corresponding to your template of 80 rows.
What you could do: In R
, eliminate those NA rows entirely, so that our dataframe now has only 77 rows.
You insert empty rows for your template via xtable
with
> addtorow <- list()
> addtorow$pos <- list()
> addtorow$pos[[1]] <- c(14,29,59)
> addtorow$command <- "\\\\ \n"
> print( xtable( o ), add.to.row = addtorow, include.rownames=FALSE )
That should give you empty lines, no &
but with \\
and thus be what you are looking for?
回答2:
If you want more flexibility you can build the table using a combination of xtable
and writeLines
. Let xtable
write the first part to file (print.xtable
, file = "bla.txt"
), then write \\
with writeLines
, and continue with xtable
. To prevent writing the header twice, set only.contents
to TRUE
. Do mind to set append
equal to TRUE
in your call to print.xtable
and writeLines
.
来源:https://stackoverflow.com/questions/12766173/xtable-package-skipping-some-rows-in-the-output