简体   繁体   中英

flextable: systematically change multiple headers' labels

I'm looking to change the S_1 through S_4 here with a one-liner, instead of typing them all out in set_header_label .

在此处输入图像描述 `

how I made up ft1

ft1 <- head(iris) %>%
  flextable() %>%
set_header_labels(
  values = list(
    Sepal.Length = "S_1",
    Sepal.Width = "S_2",
    Petal.Length = "S_3",
    Petal.Width = "S_4"
  )
)

The rough idea of the one-liner

ft1 %>%
  set_header_labels(
  values = list(list(S_1:S_4) = list(paste("\U03A3", c(1:4), sep = "_"))))

I think one approach is to create a named list separately, and then use in set_header_labels . Let me know if this is what you were looking for.

library(dplyr)
library(flextable)

my_list <- setNames(as.list(paste0("S_", 1:4)), names(iris[1:4]))

ft1 <- head(iris) %>%
  flextable() %>%
  set_header_labels(values = my_list)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM