How do I split a kable into multiple columns?

I am trying to create a "longitudinal" layout of long tables in RMarkdown with kable

. For example, I would like the table to be split into two columns like in the example below:

dd <- data.frame(state=state.abb, freq=1:50)
kable(list(state=dd[1:25,], state=dd[26:50,]))

      

However, this hack produces a result that looks worse than normal kable

output (for example, the title is not in bold). Is there a "correct" way to do this using kable

?

+3


source to share


1 answer


kable

is a great tool, but it has limitations. For the type of table you are describing, I would use one of two different tools depending on the desired result.

  • Hmisc::latex

    for .Rnw -> .tex -> .pdf

  • htmlTable::htmlTable

    for .Rmd -> .md -> .html

Here's an example of the latter:



dd <- data.frame(state=state.name, freq=1:50)
dd2 <- cbind(dd[1:25, ], dd[26:50, ])

library(htmlTable)
htmlTable(dd2,
          cgroup = c("Set 1:25", "Set 26:50"),
          n.cgroup = c(2, 2),
          rnames = FALSE)

      

enter image description here

+2


source







All Articles