Search code examples
rsweaveknitr

The use of format.pval in R (and with \Sexpr in Sweave)


I have read the help file for format.pval and was wondering if this is a right tool to output numbers with proper format as far as significant digits are concerned

In this post:

R / Sweave formatting numbers with \Sexpr{} in scientific notation

a solution was proposed and I wonder if the function format.pval is already here to do this.

And I guess that we can just use it in Sweave as \Sexpr{format.pval(a value/variable here)} together with options for the number of significant digits.

Thanks a lot...


Solution

  • format.pval is specifically designed to format printed p.values, for example when viewing the output of lm.

    The workhorse for format.pval is format which is more general in purpose. So you should probably use format or its cousins - prettyNum and formatC instead.

    Footnote: for formatting dates (POSIXct or POSIXlt) you need the date formatting function strptime