R/apa_p_value.r

Defines functions apa_p_value

Documented in apa_p_value

#' apa_p_value
#'
#' This function uses rounds p values using APA rules: No leading zero, rounded to three decimal places, below this shows as "< .001".
#' @param p p value to be formatted
#' @export
#' @examples
#' apa_p_value(0.00000004)
#' apa_p_value(0.487173)

apa_p_value <- function(p){
  p_formatted <- ifelse(p >= 0.0001, paste("=", round(p, 4)),
                        ifelse(p < 0.0001, "< .0001", NA))
  p_formatted <- gsub(pattern = "0.", replacement = ".", x = p_formatted, fixed = TRUE)
  p_formatted
}
ianhussey/timesavers documentation built on May 18, 2019, 1:28 a.m.