本文介绍了xtable包:在输出中跳过一些行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

xtable 输出中,如果我想要一些行在其中没有任何内容,我将把 NA 在与我想要跳过的行相对应的矩阵元素中。

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.

但是,这将导致xtable输出像& & & & & & & & \\ 。我想知道的是我如何做到这一点,所以它只对我希望跳过的行的 \\

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.

推荐答案

仍然不知道我是否明白,但我给它一个镜头。

Still not sure whether I understand right but I give it a shot.

我在这里做的最重要的假设是,该模板中的多列行总是在同一个位置。您可以使用R创建这些行中没有(有用的)数据的矩阵或数据框。

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.

出于本例的目的,多列行为15,30和60的数据帧为80行,对应于您的80行模板。

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.

您可以做什么:在 R ,完全消除那些NA行,这样我们的数据框现在只有77行。

What you could do: In R, eliminate those NA rows entirely, so that our dataframe now has only 77 rows.

通过 xtable

> 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?

这篇关于xtable包:在输出中跳过一些行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 10:41