Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control number of decimal places on xtable output in R

Tags:

r

xtable

I am using Rmd file to create a report and I used xtable package to create the table. The output of the xtable shows the number of decimal places upto 2 digits. Is there a way to control the decimal places in xtable ?

The sample code I used in Rmd file for the xtable is as follows:

```{r, results='asis', message=FALSE, echo=FALSE}
source("../../R code/data analysis.R")
library(xtable)
library(plyr)
table1 <- xtable(t3,caption="Table showing the Mean discharge and mean gage height on each year on each month",digits=NULL)

print.xtable(table1,type="latex",comment = getOption("xtable.comment", FALSE))

```

The output from this is as follows:

enter image description here

Here, I don't want any decimal places for year and month. Is there a way to control this thing ?

Thanks.

like image 922
Jd Baba Avatar asked Mar 18 '13 21:03

Jd Baba


1 Answers

You should use the digits parameter from xtable function correctly.

table1 <- xtable(t3,caption="Table showing the Mean discharge
and mean gage height on each year on each month",digits=c(0,0,0,3,4))

Each element of that vector represents the number of decimal fields in each column (including the first column with row.names).

like image 54
João Daniel Avatar answered Oct 16 '22 13:10

João Daniel