My problem comes from having columns that I want to format differently. I would like the same # of digits beyond the decimal point on all column, but on the final column the p-value column I'd like scientific notation to show for the really small numbers. I'd still like to have the same # of digits shown for the scientific notation beyond the decimal.
library(kableExtra)
k.table <- mlr_table3 %>%
mutate(P_value= cell_spec((formatC(x=P_value, digits=3, width = 3, format='g', flag = "-", drop0trailing = TRUE, preserve.width = "common")), "html", color = ifelse(P_value <= 0.05, yes="red", no="blue"), escape = F)) %>%
mutate_if(is.numeric, function(x) {
cell_spec((formatC(x,digits=2, width=3, format="f", flag="-", drop0trailing = FALSE)), "html")
}) %>%
kable("html", escape = FALSE, align = "l", caption = "Summarized linear model with SSC Data") %>%
kable_styling(c("striped", "bordered"), full_width = F) %>%
column_spec(1, bold = T)
print.knitr_kable(k.table)
Right now the table looks like this
Summarized linear model with SSC Data
term estimate std.error statistic P_value
(Intercept) 14.93 0.35 43.24 1.06e-173
Cortland -5.58 1.00 -5.58 3.86e-08
Fire -4.00 1.68 -2.38 0.0179
Frost -1.64 1.09 -1.51 0.132
Haral -5.32 1.09 -4.90 1.28e-06
HoneyA -4.81 1.11 -4.35 1.63e-05
HoneyB -0.97 1.09 -0.89 0.373
Sake -2.12 1.09 -1.95 0.0517
Mac -1.88 1.14 -1.65 0.1
Sweet -1.71 1.09 -1.57 0.116