【问题标题】:How to change the column names in gt?如何更改gt中的列名?
【发布时间】:2021-10-25 16:56:02
【问题描述】:

如何使用 R 中的 gt 包在列名中添加括号 ()? r = grp35_rs12468485 中的列名。我想要的:grp35(rs12468485)

我已经用 gt 包创建了一个表:

table1_pgx <- 
    pgx_rs %>% 
    gt() %>%
  tab_header(
    title = md("pgx")

谢谢!

【问题讨论】:

    标签: r gt


    【解决方案1】:

    解决方法可以在:https://gt.rstudio.com/articles/intro-creating-gt-tables.html

    对我来说这很有效:

    pgx_table <- pgx_rs %>% 
        gt() %>%
      tab_header(
        title = md("pgx")) %>%
          cols_label(
            grp35_rs12468485 = html("gpr35(rs12468485)")
          )
    

    【讨论】:

      【解决方案2】:

      您是否正在寻找这样的解决方案:在 iris 示例数据集中,. 之后的字符串包含在所有列名的括号中。在您的情况下,您可以将 . 替换为 _

      library(gt)
      library(dplyr)
      iris %>% 
        as_tibble() %>% 
        rename_with(~str_c(str_replace(., "\\.", "("), ")")) %>% 
        gt() 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-14
        • 1970-01-01
        • 2013-05-27
        • 2022-01-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多