Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

gtsummary

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!

like image 767
veronicalm Avatar asked Nov 15 '25 08:11

veronicalm


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)

like image 185
Daniel D. Sjoberg Avatar answered Nov 18 '25 05:11

Daniel D. Sjoberg