Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for multiway table? #12

Open
xinkai-zhou opened this issue Jan 14, 2016 · 2 comments
Open

support for multiway table? #12

xinkai-zhou opened this issue Jan 14, 2016 · 2 comments

Comments

@xinkai-zhou
Copy link

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)
```  ```
@yihui
Copy link
Owner

yihui commented Jan 14, 2016

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" :)

@friendly
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants