Reputation: 93
I have looked at other answers on this subject but can't seem to get it to work - I am trying not show any decimal places in my output table but they keep appearing. Using knitr:
{r cyclist_proportions, echo=FALSE, results='asis', warning=FALSE}
print(xtable(cyclist_proportions), digits=c(0,0), type='html', include.rownames=FALSE)
The values are numeric:
'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
I did try digits=c(0,0,0) in case I needed to allow for the rownames but it made no difference - the values always have two decimal places.
Thanks
UPDATE
Thank you for the answers, they both helped me solve it. I was mixing up the arguments of xtable and print.xtable.
So now in my script file I have
cyclist_proportionstab <- xtable(cyclist_proportions)
digits(cyclist_proportionstab) <- 0
and in my R markdown file
```{r cyclist_proportions, echo=FALSE, results='asis', warning=FALSE}
print.xtable(cyclist_proportionstab, include.rownames = FALSE, type='html')
```
which works
Upvotes: 1
Views: 1350
Reputation: 5424
I use
summtab <- xtable(summdf, caption = "Number of obs by some other variable")
names(summtab)<-c("Categorical var", "n obs", "Per cent")
digits(summtab)[3] <- 0
print(summtab, include.rownames = FALSE, booktabs = TRUE, sanitize.text.function = identity)
for making nice tables of dataframes, where [3] counter-intuitively indexes the second column of the dataframe.
Upvotes: 1