Control number of decimal places on xtable output in R

拜拜、爱过 提交于 2019-11-26 20:49:41

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/15487421/control-number-of-decimal-places-on-xtable-output-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!