I have a gt table similar to the one in the example below. Some of the summary_rows and grand_summary_rows are comma formatted but others are not. Question: how can I format the entire gt table so that all the rows are comma formatted? I know about big.mark ="," but couldn’t find a way to add it to the code.
library(gt)
library(tidyverse)
sp500 %>%
dplyr::filter(date >= "2015-01-05" & date <= "2015-01-16") %>%
dplyr::arrange(date) %>%
dplyr::mutate(week = paste0("W", strftime(date, format = "%V"))) %>%
dplyr::select(-adj_close, -volume) %>%
gt(
rowname_col = "date",
groupname_col = "week"
) %>%
grand_summary_rows(
columns = c(open, high, low, close),
fns = list(
min = ~min(.),
max = ~max(.),
avg = ~mean(.)),
formatter = fmt_number,
use_seps = FALSE
)
>Solution :
Reproducible example is always welcome. With this data, you may use this code:
sp500 %>%
dplyr::filter(date >= "2015-01-05" & date <= "2015-01-16") %>%
dplyr::arrange(date) %>%
dplyr::mutate(week = paste0("W", strftime(date, format = "%V"))) %>%
dplyr::select(-adj_close, -volume) %>%
gt(
rowname_col = "date",
groupname_col = "week"
) %>% fmt_number(columns = 2:5, decimals = 2, sep_mark = ".", dec_mark = ",") %>%
grand_summary_rows(
columns = c(open, high, low, close),
fns = list(
min = ~min(.),
max = ~max(.),
avg = ~mean(.)),
formatter = fmt_number,
use_seps = FALSE
)
That gives the result:
2.054,44 2.054,44 2.017,34 2.020,58
Hope this help.