r - gt表R正文中的下标和上标
问题描述
如何在 R 中获取我的 gt 表以显示下标/上标?我希望同位素列中的数字显示为上标。
library(gt)
Isotope <- c("1H", "2H", "16O", "17O", "18O")
Abundance <- c(0.99985, 0.00015, 0.99757, 0.00038, 0.00205)
table <- as.data.frame(cbind(Isotope, Abundance))
table %>% gt()
解决方案
实现所需结果的一种选择是使用gt::text_transform
HTML<sup>
标签,如下所示:
library(gt)
library(stringr)
Isotope <- c("1H", "2H", "16O", "17O", "18O")
Abundance <- c(0.99985, 0.00015, 0.99757, 0.00038, 0.00205)
table <- data.frame(Isotope, Abundance)
table %>% gt() %>%
text_transform(
locations = cells_body(
columns = c(Isotope)
),
fn = function(x){
sup <- str_extract(x, "^\\d+")
text <- str_extract(x, "[^\\d]+")
glue::glue("<sup>{sup}</sup>{text}")
}
)
推荐阅读
- javascript - 如何使用双斜杠(//)捕获/检查所有 URL 并更正它们(JQuery?)
- opc-ua - 在 WINDEV 上使用 OPC UA 将一个数组(实数)写入 Siemens 1500
- eclipse - 使用 eclipse 将自动化测试与 azure devops 中的测试用例相关联
- elasticsearch - Elasticsearch 术语聚合不返回存储桶
- random-forest - 在分位数随机森林回归模型中检查树木
- csv - CSV - 如何在一个单元格中表示多个值
- amazon-web-services - 更新 EBS 卷的大小而不替换旧卷并重启 EC2 实例
- python - 如何使用 for 循环在 Python 中绘制子图
- java - 不能跑扑医生--执照
- regex - 用于在 Google Data Studio 中提取年份或月份的 REGEXP_EXTRACT 特定字符串