r - 使用flextable在表格的不同部分之间共享脚注

标签 r flextable footnotes

我需要在表格的标题和正文中放置相同的脚注来创建表格,我无法弄清楚如何使用 flextable 来实现它,我可以创建的内容如下:

library(flextable)
library(dplyr)
library(tidyr)

data(iris)
iris %>%
  as_tibble %>%
  gather(.,key = variable,value = value,-Species) %>%
  group_by(Species,variable) %>%
  summarise(value=formatC(mean(value),digits = 2,format = 'f')) %>%
  ungroup %>%
  spread(.,key = variable,value = value) %>%
  flextable %>%
  footnote(.,part = 'header',i = 1,j = c(2:5),
           value = as_paragraph(c('Rounded to two decimal places')),
           ref_symbols = c('*'),
           inline=FALSE) %>%
  footnote(.,part = 'body',i = c(1:3),j = 1,
           value = as_paragraph(c('Rounded to two decimal places')),
           ref_symbols = c('*'),
           inline=FALSE)

目前我用相同的语句为标题和正文创建了两个脚注,我想知道是否可以将这两个语句合并为一个。

谢谢!

最佳答案

(我没想到在实现此功能时脚注会重复)通过使用 merge_v , 如果相同,您可以合并它们:

library(flextable)
library(dplyr)
library(tidyr)

data(iris)
iris %>%
  as_tibble %>%
  gather(.,key = variable,value = value,-Species) %>%
  group_by(Species,variable) %>%
  summarise(value=formatC(mean(value),digits = 2,format = 'f')) %>%
  ungroup %>%
  spread(.,key = variable,value = value) %>%
  flextable %>%
  footnote(.,part = 'header',i = 1,j = c(2:5),
           value = as_paragraph(c('Rounded to two decimal places')),
           ref_symbols = c('*'),
           inline=FALSE) %>%
  footnote(.,part = 'body',i = c(1:3),j = 1,
           value = as_paragraph(c('Rounded to two decimal places')),
           ref_symbols = c('*'),
           inline=FALSE) %>% 
  merge_v(part = "footer")


enter image description here

关于r - 使用flextable在表格的不同部分之间共享脚注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62148912/

相关文章:

jquery - 使用 jQuery 向同一文本添加多种样式

reactjs - React - 子组件的运行计数(例如脚注)

markdown - 如何更有效地将脚注插入 Hexo 帖子中?

使用插入符号包运行 cforest with controls = cforest_unbiased()

r - 从数据框列表中将选定的数据框添加到一起

r - 如何在 R 中使用 dplyr 包重现这个 "apply"示例?

r-markdown - 编织到 MS Word 时,波斯语/波斯语/阿拉伯语文本未显示在 Rmarkdown officedown/flextable 中

r - sparkR 中的 socketConnection 错误

r - 保存 R 中循环内生成的绘图

r - 自定义弹性表中标题的颜色?