我有一个功能,这是创建一个横幅列表逐个表.但现在我想将它们显示为作为cind的绑定.
我能够通过列绑定表格,但不能使横幅作为表格的标题.此外,我还想删除像N.X,N.Y这样的名字.我只想保持N,我需要一个灵活的输出
currently table is coming like below
library(knitr)
library(tidyverse)
library(flextable)
banner <- c("All","Other")
t1 <- structure(list(` ` = c("CA", "USA","UK", "GER", "Italy","France", "China"),
Local = c("38%", "58%","71%", "78%", "91%", "91%", "84%"),
Outsider = c("43%", "28%", "29%"," 9%", " 7%", " 4%", " 5%"),
Mixed = c("19%","13%", " 0%", "13%", " 1%", " 5%", "11%"),
N = c("9999", "9999","9999", "9999", "9999", "9999", "9999")), row.names = c(NA, -7L), class = "data.frame")
t2 <- structure(list(` ` = c("CA", "USA","UK", "GER", "Italy","France", "China"),
Local = c("71%", "93%","96%", "96%", "96%", "96%", NA),
Outsider = c(" 7%", " 4%", " 4%"," 0%", " 0%", " 0%", NA),
Mixed = c("21%"," 4%", " 0%", " 4%", " 4%", " 4%", NA),
N = c("2800", "2800","2800", "2800", "2800", "2800", NA)), row.names = c(NA, -7L), class = "data.frame")
tl <- list(t1,t2)
fun1 <- function(tl,banner){
t_list1<-list()
for (i in 1:length(banner))
{
t_list <- list()
t_list1[[i]] <- tl[[i]]
}
t1<-Reduce(function(...)merge(...,all=TRUE,by=" "),t_list1)
t1 <- t1 %>% flextable()
t1
}
fun1(tl=tl,banner = banner)
输出应如下所示