0

I am trying to create a table in RMarkdown that looks similar to the following example:

---
title: "Example"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```


```{r cars, echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(Hmisc)
latex(mtcars, file = "", cgroup = c("mpg", "cyl"), n.cgroup = c(1,10))
```

I would like to group columns 2 through 10. Any ideas on how I can accomplish this with the Hmisc package or any other R package?

rjss
  • 935
  • 10
  • 23

2 Answers2

2

I think just using a blank header name for the first column gives you what you want:

latex(mtcars, file = "", cgroup = c("", "cyl"), n.cgroup = c(1,10))

Result:

enter image description here

Marius
  • 58,213
  • 16
  • 107
  • 105
  • Great! Is it possible to align the rowname (`mtcars`) to the bottom (similar to `mpg`)? – rjss Feb 13 '18 at 00:49
0

Using my package:

library(huxtable)
hux_cars <- as_hux(mtcars, add_colnames = TRUE)
hux_cars <- insert_row(hux_cars, c('mtcars', 'cyl', rep('', 9)))
colspan(hux_cars)[1, 2] <- 10
align(hux_cars)[1, 2] <- 'centre'
bold(hux_cars)[1, ] <- TRUE
position(hux_cars) <- 'left'
quick_pdf(hux_cars)

Which produces: top of the table