The cells_grand_summary() function
Use countrypops to create a gt table. Add some styling to a grand summary cell with with tab_style() and cells_grand_summary().
countrypops |>
dplyr::filter(country_name == "Spain", year < 1970) |>
dplyr::select(-contains("country")) |>
gt(rowname_col = "year") |>
fmt_number(
columns = population,
decimals = 0
) |>
grand_summary_rows(
columns = population,
fns = change ~ max(.) - min(.),
fmt = ~ fmt_integer(.)
) |>
tab_style(
style = list(
cell_text(style = "italic"),
cell_fill(color = "lightblue")
),
locations = cells_grand_summary(
columns = population,
rows = 1
)
)
|
population |
| 1960 |
30,455,000 |
| 1961 |
30,739,250 |
| 1962 |
31,023,366 |
| 1963 |
31,296,651 |
| 1964 |
31,609,195 |
| 1965 |
31,954,292 |
| 1966 |
32,283,194 |
| 1967 |
32,682,947 |
| 1968 |
33,113,134 |
| 1969 |
33,441,054 |
| change |
2,986,054 |