how to get rid of leading zeros in the tables created by gtsummary package in R?

Viewed 90

I wonder if there is an easy way to get rid of the leading zeros in the regression tables created by gtsummary package in R? I love this package for its functionality but not sure if there is an easy way to format the table to comply with APA guidelines (e.g., no leading zeros for p values)? Thanks!

1 Answers

Use the argument tbl_regression(pvalue_fun=) to change the way the p-values are rounded and formatted. Example below!

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.4.1'

# formatting function for p-values that removes leading 0
apa_pvalues <- function(x) {
  style_pvalue(x, digits = 2) %>%
    stringr::str_replace("0.", ".")
}

tbl <- 
  lm(marker ~ age + grade, trial) %>%
  tbl_regression(pvalue_fun = apa_pvalues)

enter image description here Created on 2021-07-09 by the reprex package (v2.0.0)

Related