2

I try to set the number of digits when exporting in latex the result of describe() function.

MWE:

require("Hmisc")
dat <- rnorm(1000,mean = 0, sd = 1)
latex(describe(dat, digits=2))

produces the following output:

enter image description here

The digits argument does not seem to have any effect: nor the means values, nor the min/max values have the number of digits modified. Any idea to set the number of digits?

  • Can you be a little more specific, what is your question? – Dinesh.hmn Oct 10 '17 at 19:21
  • I want to display a limited number of digits wether in the low/high values or in the statistics (mean, quantiles, etc) – Benoit Lamarsaude Oct 10 '17 at 20:04
  • Your question seems very similar to this: https://stackoverflow.com/questions/31712030/control-digits-printed-by-hmisclatex-on-a-psych-object Does the answer for that one help? – shea Oct 10 '17 at 21:25

1 Answers1

1

The digits argument of describes is used to set options(digits = digits).
That is, digits specifies the minimum number of significant digits to be printed (see ?options).
We start considering a vector of random numbers with mean=5, sd=1, and set digits=2.

library(Hmisc)
oldopt <- options("digits")
set.seed(1)
dat <- rnorm(1000, mean = 5, sd = 1)
dgts <- 2
dscr <- describe(dat, digits=dgts)
options(digits = dgts)
outltx <- latex(dscr, file="describe.tex")
dvips(outltx)
options(digits = oldopt$digits)

The output is:

enter image description here

Here the minimum number of significant digits is 2: one digit before and one after the decimal point (for example, the 95th percentile is 6.7).

Now we consider a vector of random numbers with mean=0, sd=0.01, and set digits=2.

oldopt <- options("digits")
set.seed(1)
dat <- rnorm(1000, mean = 0, sd = 0.01)
dgts <- 2
dscr <- describe(dat, digits=dgts)
options(digits = dgts)
outltx <- latex(dscr, file="describe.tex")
dvips(outltx)
options(digits = oldopt$digits)

enter image description here

Again, the minimum number of significant digits is 2; The median (.50), for example, is -0.00035, that is, it has 2 significant digits (3 and 5).

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58