Digits after decimal point in pandoc.table
pflick opened this issue · comments
It seems that the digits option in pandoc.table results in the total number of digits, not digits after the decimal. Here is an example:
a<-c(10.12304,9.321,0.12345,82.77123)
b<-c(12.0009,1.0987,0.9876,4.3321)
tbl<-rbind(a,b)
pandoc.table(tbl, digits=4)
results in
------- ------- ------- -------- -------
**a** 10.12 9.321 0.1235 82.77
**b** 12 1.099 0.9876 4.332
------- ------- ------- -------- -------
There doesn't seem to be a way to get x digits after the decimal point if your numbers vary in length. Is this a feature that could be added?
Thank you for pander!
Yeah, so digits
stands for the number of signigicant digits as in format
. I think you are looking for a mix of digits
and round
, eg:
> pandoc.table(tbl, digits=4, round = 4, keep.trailing.zeros = TRUE)
------- ------- ------- -------- --------
**a** 10.12 9.321 0.1234 82.771
**b** 12.00 1.099 0.9876 4.332
------- ------- ------- -------- --------
Or even more:
> pandoc.table(tbl, digits=5, round = 4, keep.trailing.zeros = TRUE, justify = 'right')
------- -------- -------- -------- ---------
**a** 10.123 9.3210 0.1234 82.7712
**b** 12.001 1.0987 0.9876 4.3321
------- -------- -------- -------- ---------
I hope this helps and closing the ticket for now -- as having no better idea around this, but feel free to come back with suggestions and reopen.