stocks_summarized <- stocks1 %>%
group_by(month_end, year_end) %>%
summarize(value = mean(value, na.rm = TRUE), .groups = "drop")
valid_months <- c("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")
stocks_summarized <- stocks_summarized %>%
filter(month_end %in% valid_months)
stocks_wide <- stocks_summarized %>%
pivot_wider(
names_from = year_end,
values_from = value
) %>%
arrange(factor(month_end, levels = month.name)) %>%
mutate(across(where(is.numeric), ~ ifelse(is.na(.), "-", as.character(round(. / 2, 1))))) %>%
rename(Month = month_end) %>%
select(Month, `1990`, everything())
# Displaying the formatted table with kableExtra
stocks_wide %>%
kable(format = "html", caption = "Monthly Values by Year") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"),
full_width = FALSE,
position = "left") %>%
row_spec(0, bold = TRUE, color = "white", background = "#4e79a7") # Custom header styling