knitr - xtable R - can't get rid of decimal places -


i have looked @ other answers on subject can't seem work - trying not show decimal places in output table 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 numeric:

   'data.frame':    5 obs. of  2 variables:  $ percentage of casualties cyclists: num  7 8 8 9 10  $ year                                           : num  2008 2009 2010 2011 2012 

i did try digits=c(0,0,0) in case needed allow rownames made no difference - values have 2 decimal places.

thanks

update

thank answers, both helped me solve it. mixing arguments of xtable , print.xtable.

so in script file have

cyclist_proportionstab <- xtable(cyclist_proportions) digits(cyclist_proportionstab) <- 0 

and in r markdown file

```{r cyclist_proportions, echo=false, results='asis', warning=false} print.xtable(cyclist_proportionstab, include.rownames = false, type='html') ``` 

which works

i use

summtab <- xtable(summdf, caption = "number of obs 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, [3] counter-intuitively indexes second column of dataframe.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

angularjs - ng-repeat duplicating items after page reload -