Data
a <- c("Green", "Red", "Blue", "Orange")
b <- c(100, 408, 39, 102)
c <- c(12000, 3100, 2410, 503)
d <- c("*", "*", "*", "***")
data <- data.frame(a, b, c, d)
data %>%
gt()
Say I have the above dataframe. Is there a way to make the asterixs in column d, a superscript of column c? So c looks like: 12000^* 3100^* etc?
I am using the gt
package for tables...
CodePudding user response:
One option would be to first create an HTML string using e.g. glue::glue
, then use gt::fmt_markdown()
to render the text as HTML:
library(gt)
library(dplyr)
data |>
mutate(c = glue::glue("{c}<sup>{d}</sup>")) |>
select(-d) |>
gt() |>
fmt_markdown(columns = c)