Control number of decimal places on xtable output in R

r, xtable

Solution

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

Problem

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: Here, I don't want any decimal places for year and month. Is there a way to control this thing ? Thanks.

Original source