Created
December 15, 2016 08:18
-
-
Save jrnold/64e69c2f5767b7ea94ebae658951f1a0 to your computer and use it in GitHub Desktop.
p-value formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(stringr) | |
| library(dplyr) | |
| drop_leading0 <- function(x) { | |
| str_replace(x, "\\b0+\\.(?=[0-9])", ".") | |
| } | |
| format_pval <- function(x, eps = 0.001, digits = 2, drop = TRUE) { | |
| ret <- if_else( | |
| x < eps, | |
| str_c("<",as.character(eps)), | |
| formatC(x, digits = digits, format = "f") | |
| ) | |
| if (drop) { | |
| ret <- drop_leading0(ret) | |
| } | |
| ret | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple function to format p-values (truncate at a lower value, and drop leading 0's).