R/formatPvalue.R

Defines functions formatPvalue

Documented in formatPvalue

### Function to format p values nicely
formatPvalue <- function(values, digits = 3, spaces=TRUE, includeP = TRUE) {
  missingValues <- is.na(values);
  values <- ifelse(values < 0, 0, ifelse(values > 1, 1, values));
  pchar <- ifelse(includeP, "p = ", "");
  eps <- 10 ^ -digits;
  res <- paste0(pchar, noZero(format.pval(round(values, digits),
                                          eps=eps, digits=digits,
                                          scientific=digits+1)));
  if (spaces) {
    res <- gsub("= <", "< ", res);
  } else {
    res <- gsub("= <", "<", res);
    res <- gsub(" ", "", res);
  }
  res <- ifelse(missingValues, NA, res);
  return(res);
}

Try the userfriendlyscience package in your browser

Any scripts or data that you put into this service are public.

userfriendlyscience documentation built on Nov. 18, 2017, 4:14 a.m.