I have the following data table .
library(dplyr)
library(gt)
df <- tibble(
`model 2000` = c("a", "b"),
`car 2022` = c("f", "d")
)
I would like to loop over a vector of column names and perform a string replace, then append this to the gt table
my_cols <- colnames(df)
for(i in my_cols){
df <- df %>%
gt() %>%
cols_label(
i = str_trim(str_remove(i, "2020|2021|2022"))
)
df
}
I want to be able to change the names after the GT table is created using this for loop but when the loop passes the values in my_cols, they aren't recognized... any help?
Here is the error:
Error: All column names provided must exist in the input `.data` table.
