I have the data frame... df <- cbind(expand.grid(d=as.factor(c(2,5)), n=c(100, 200), beta=as.factor(c(0.2, 0.8)), group=LETTERS[1:2]), value=runif(16)) ... which I would like to display in a table like ... require(tables) tabular(d * beta ~ group * mean * Heading() * value, data=df) Now I would like to insert (vertical) space between every other line of the table. I checked the manual and vignette of 'tables', but it only covers the case when there is just one variable specified in the left-hand side of the formula (so "to the left" of "~"). I tried to adapt the idea of using RowFactor() ... tabular(RowFactor(1:4, "", spacing=2, space=0.5) + d * beta ~ group * mean * Heading() * value, data=df) ... but obtain ... Error in `colnames<-`(`*tmp*`, value = "") : length of 'dimnames' [2] not equal to array extent Cheers, Marius
How to insert vertical space between lines of tables created with the R package 'tables'?
3 messages · Marius Hofert, Duncan Murdoch
On 12-09-08 11:41 AM, Marius Hofert wrote:
I have the data frame... df <- cbind(expand.grid(d=as.factor(c(2,5)), n=c(100, 200), beta=as.factor(c(0.2, 0.8)), group=LETTERS[1:2]), value=runif(16)) ... which I would like to display in a table like ... require(tables) tabular(d * beta ~ group * mean * Heading() * value, data=df) Now I would like to insert (vertical) space between every other line of the table. I checked the manual and vignette of 'tables', but it only covers the case when there is just one variable specified in the left-hand side of the formula (so "to the left" of "~"). I tried to adapt the idea of using RowFactor() ... tabular(RowFactor(1:4, "", spacing=2, space=0.5) + d * beta ~ group * mean * Heading() * value, data=df) ... but obtain ... Error in `colnames<-`(`*tmp*`, value = "") : length of 'dimnames' [2] not equal to array extent
The + means concatenation, so that spec says to put the RowFactor above the d*beta rows. Not sure why that causes an error, but it's likely because you've got the wrong number of items. This should work, but it doesn't give you the extra spacing properly. I didn't think anyone would want extra spacing on every level. I'll put in a patch to fix it; look for an update on R-forge. tabular(RowFactor(d, spacing=1, space=0.5) * beta ~ group * mean * + Heading() * value, data=df) Duncan Murdoch
Duncan Murdoch <murdoch.duncan at gmail.com> writes:
The + means concatenation, so that spec says to put the RowFactor above the d*beta rows. Not sure why that causes an error, but it's likely because you've got the wrong number of items. This should work, but it doesn't give you the extra spacing properly. I didn't think anyone would want extra spacing on every level. I'll put in a patch to fix it; look for an update on R-forge. tabular(RowFactor(d, spacing=1, space=0.5) * beta ~ group * mean * + Heading() * value, data=df) Duncan Murdoch
Thanks a lot, Duncan. In the minimal example, I have two variables (d and beta) that create "blocks" of rows showing similar results. Assume you have three (say, d, beta, and alpha in columns 1, 2, and 3, respectively). I typically separate blocks with the same d by a larger space, then blocks with the same beta with a smaller space (and blocks with the same alphas with no space). So this would look like: tabular(RowFactor(d, spacing=2, space=0.5) * RowFactor(beta, spacing=2, space=0.25) * alpha ~ group * mean * Heading() * value, data=df) ... with appropriate "spacing" arguments. I find this visually quite appealing. Cheers, Marius