Skip to navigation

Nicely formatted p values in Sweave

R function:

pval <- function (x) {
 ifelse(x$p.value<.001,paste("<",.001),paste("=",round(x$p.value,2)))
}

For any p < 0.001, this will output "p < 0.001", else it will give the exact value (e.g. p = .04). Then, in the latex part of your document, refer to it as:

\Sexpr{pval(T.TEST)}

where T.TEST is a t.test (either direct code or an object).

Comments are closed.