printr icon indicating copy to clipboard operation
printr copied to clipboard

support for multiway table?

Open xinkai-zhou opened this issue 9 years ago • 2 comments

printr gives beautiful output for table(). Is there any plan for supporting multi-way table generated by ftable()?

An RMD example:


---
title: "Untitled"
author: ""
date: ""
output: pdf_document

---


```{r, echo=FALSE}
library(knitr)
library(printr)
table(mtcars[c("cyl", "vs", "am", "gear")])
ftable(mtcars[c("cyl", "vs", "am", "gear")],
       row.vars = 1:3)
```  ```

xinkai-zhou avatar Jan 14 '16 19:01 xinkai-zhou

No, I don't have such a plan yet. As long as you can convert the ftable output to a regular matrix or data frame, the rest will be easy. For the particular case you mentioned, I guess one way to go is to convert

          gear  3  4  5
cyl vs am              
4   0  0        0  0  0
       1        0  0  1
    1  0        1  2  0
       1        0  6  1
6   0  0        0  0  0
       1        0  2  1
    1  0        2  2  0
       1        0  0  0
8   0  0       12  0  0
       1        0  0  2
    1  0        0  0  0
       1        0  0  0

to something like this

cyl vs am/gear  3  4  5
4   0  0        0  0  0
       1        0  0  1
    1  0        1  2  0
       1        0  6  1
6   0  0        0  0  0
       1        0  2  1
    1  0        2  2  0
       1        0  0  0
8   0  0       12  0  0
       1        0  0  2
    1  0        0  0  0
       1        0  0  0

but this approach does not generalize to more complicated ftables like

       am    0        1      
       gear  3  4  5  3  4  5
cyl vs                       
4   0        0  0  0  0  0  1
    1        1  2  0  0  6  1
6   0        0  0  0  0  2  1
    1        2  2  0  0  0  0
8   0       12  0  0  0  0  2
    1        0  0  0  0  0  0

Personally I don't have much interest beyond simple rectangular tables. If you want to work on it, all I can say is "pull requests are welcome" :)

yihui avatar Jan 14 '16 22:01 yihui

It is possible that vcd::structable() might give a data structure that is easier to work with

friendly avatar Jun 11 '16 02:06 friendly