library(dplyr)
library(purrr)
library(knitr)
df <- tibble(
letter = sample(letters[1:10], 100, replace = TRUE),
nums = rep(1:10, 10),
a = rnorm(100),
b = rnorm(100),
c = rnorm(100),
d = rnorm(100)
)
df %>%
split(.$letter) %>%
map(~ group_by(., nums) %>%
summarise(a = sum(a)) %>%
kable(caption = paste("it is table", substitute(.)))
)
如上面的代码所示,我想在数据框被拆分后设置类似“它是表a”,“它是表b”......的标题。
答案 0 :(得分:2)
这需要是一个%>%
管道吗?否则,您可以通过两个步骤轻松完成:
summarized <- df %>%
split(.$letter) %>%
map(~ group_by(., nums) %>%
summarise(a = sum(a)))
lapply(names(summarized), function(letter)
kable(summarized[letter], caption = paste("it is table", letter)))
Markdown表格在kable()
中没有字幕。使用format="html"
或format="latex"
获取支持字幕的输出格式。