31

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.

James Trimble
  • 1,868
  • 13
  • 20
Jd Baba
  • 5,948
  • 18
  • 62
  • 96

1 Answers1

62

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).

João Daniel
  • 8,696
  • 11
  • 41
  • 65
  • @ Joao : Thank you so much for your answer. Actually, I had seen the digits but I didn't know whether we could use array or not. Thanks. – Jd Baba Mar 18 '13 at 22:25