How to split kable over multiple columns?

喜你入骨 提交于 2019-12-10 14:14:38

问题


I am trying to produce a "longitudinal" layout for long tables in RMarkdown with kable. For example, I would like a table to be split over 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 an output that looks a way worse than the normal kable output (for example the header is not in bold). Is there a "proper" way to do this using kable?


回答1:


kable is a great tool, but has limits. For the type of table you're describing I would use one of two different tools depending on output wanted.

  • Hmisc::latex for .Rnw -> .tex -> .pdf

  • htmlTable::htmlTable for .Rmd -> .md -> .html

Here is 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)



来源:https://stackoverflow.com/questions/43984289/how-to-split-kable-over-multiple-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!