【发布时间】:2014-03-06 10:40:13
【问题描述】:
我在这个主题上查看了other answers,但似乎无法让它工作 - 我试图在我的输出表中不显示任何小数位,但它们一直出现。使用 knitr:
{r cyclist_proportions, echo=FALSE, results='asis', warning=FALSE}
print(xtable(cyclist_proportions), digits=c(0,0), type='html', include.rownames=FALSE)
值是数字:
'data.frame': 5 obs. of 2 variables:
$ Percentage of all casualties that were cyclists: num 7 8 8 9 10
$ Year : num 2008 2009 2010 2011 2012
我确实尝试了 digits=c(0,0,0) 以防我需要允许行名,但它没有区别 - 值总是有两位小数。
谢谢
更新
感谢您的回答,他们都帮助我解决了这个问题。我混淆了 xtable 和 print.xtable 的参数。
所以现在在我的脚本文件中
cyclist_proportionstab <- xtable(cyclist_proportions)
digits(cyclist_proportionstab) <- 0
在我的 R markdown 文件中
```{r cyclist_proportions, echo=FALSE, results='asis', warning=FALSE}
print.xtable(cyclist_proportionstab, include.rownames = FALSE, type='html')
```
哪个有效
【问题讨论】:
-
print.xtable没有digits参数,因此忽略它。xtable(cyclist_proportions, digits=0)应该可以解决问题。 -
不是重复的(我在第一篇文章中链接到同一页面)
-
我看到了,但您没有遵循该答案中给出的建议,即
digits作为xtable中的参数。