I am trying to output a table using pander in a .rmd file as a pdf with 2 digits following the decimal point, but I get no digits using the following rmd:
---
title: "Long table test"
output: pdf_document
---
Here is a table:
```{r setup}
library (data.table)
library (pander)
set.seed(1984)
longString <- "description string"
dt <- data.table(id=c(1:3),description=rep(longString,3),value=rnorm(3,mean=10000,sd=1))
```
```{r pander-table}
panderOptions('round',2)
panderOptions('digits',2)
panderOptions('keep.trailing.zeros',TRUE)
pander(dt, split.cell = 80, split.table = Inf)
```
results in
-------------------------------
id description value
---- ------------------ -------
1 description string 10000
2 description string 10000
3 description string 10001
-------------------------------
Would like to see
----------------------------------
id description value
---- ------------------ ----------
1 description string 10000.41
2 description string 9999.68
3 description string 10000.64
----------------------------------
signif( mean(rnorm(1000,1000)), 2)
returns[1] 1000
. Andsignif( mean(rnorm(10,1000, 200)), 2)
returns[1] 990
– Euphorbiaceousdigits
to 7. – Moorish9999.677
(i.e. 3 digits after decimal place) or10000.64
. If I set digits to 7 and round to 2panderOptions('digits',7); panderOptions('round',2)
then I get the desired result. Seems like more of a work around than a general solution since it cannot be applied consistently to all data, I need to know how many digits I will have in my data and adjust appropriately. It would be nice if pander behaved in a similar way tokable(x, digits=2)
which results in 2 digits after the decimal. – Saraannknitr::kable
passesdigits
toround
-- what you can achieve inpander
as well by settinground
to2
, I think this is pretty sane and provides great flexibility. What's wrong with setting a largedigits
andround
to2
? – Moorish