Skip to content

Instantly share code, notes, and snippets.

@artemklevtsov
Last active January 29, 2016 21:55
Show Gist options
  • Save artemklevtsov/2b8a84038ce8349857af to your computer and use it in GitHub Desktop.
Save artemklevtsov/2b8a84038ce8349857af to your computer and use it in GitHub Desktop.
Source at gtools::stars.pval
format_pval <- function(x, cut = 0.05) {
x <- round(x, 3)
x[x == 0] <- paste("<span style='color:red;'>&lt;", 0.001, "</span>")
x[x < cut] <- paste0("<span style='color:red;'>", x[x < cut], "</span>")
return(x)
}
stars_pval <- function(x) {
unclass(symnum(x, corr = FALSE, na = FALSE, legend = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c("***", "**", "*", ".", " ")))
}
@artemklevtsov
Copy link
Author

Example:

stars_pval(c(0.5, 0.1, 0.05, 0.01, 0.001))
#> [1] " "   "."   "*"   "**"  "***"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment