Tables with column- and row-percentages using pander and CrossTable?

1k views Asked by At

I am trying to generate reports with knitr and pander.To display row- or column-percentages in a table I would like to use the CrossTable() function and get rid of values of Chi-square contribution and the table total.

Here is an example:

 ```{r}
x <- c(1,1,2,2)

y <- c(1,2,1,2)

CrossTable(x, y, prop.chisq=FALSE, prop.t = FALSE)

works quite well but

pander(descr::CrossTable(x, y, prop.chisq=FALSE, prop.t = FALSE), split.table = Inf)
  ```

results in an error message:

  Quitting from lines 45-78 (test.Rmd) Fehler in apply(x$prop.tbl, c(1, 2), to.percent):   dim(X) must have a positive length Calls: ... eval -> eval -> pander -> pander.CrossTable -> apply

How can I produce a table with only row- and column-percentages using pander and CrossTable?

Kind regards, Maller

1

There are 1 answers

0
daroczig On BEST ANSWER

This has been fixed in the development version of pander with a recent commit:

> pander(descr::CrossTable(x, y, prop.chisq=FALSE, prop.t = FALSE), split.table = Inf)

------------------------------------
 &nbsp;      1        2      Total  
--------- -------- -------- --------
**1**\    &nbsp;\  &nbsp;\  &nbsp;\ 
  N\        1\       1\       2\    
Row(%)\    50%\     50%\      50%   
Column(%)   50%      50%            

**2**\    &nbsp;\  &nbsp;\  &nbsp;\ 
  N\        1\       1\       2\    
Row(%)\    50%\     50%\      50%   
Column(%)   50%      50%            

  Total     2\       2\        4\   
            50%      50%            
------------------------------------