HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

3-way frequency table with kable #104

Open philipp-stdr opened 8 years ago

philipp-stdr commented 8 years ago

@christophergandrud Hi, I'm struggling to knit a 3-way frequency table with row probabilities. I thought I could use the kable function.

This is the code of my table:

`## 3-Way Frequency Table

Gender, income and Spouse Work Status (row probabilities)

ge_sp_ca1 <- table(z$sexcat[z$educat==4 & z$married==1], z$income_status[z$educat==4 & z$married==1], z$spwrkcat[z$educat==4 & z$married==1]) ftable(prop.table(ge_sp_ca1, c(1,2)))`

Which yields the following output: image

I thought I could use a simple kable command to knit it but it produces a completely wrong table:

knitr::kable(ftable(prop.table(ge_sp_ca,c(1,2))), caption = "Gender and Spouse Work Status",digits = 2)

2016-05-08 10 46 36 am

Any ideas how to fix this?

Thanks a lot! Philipp

christophergandrud commented 8 years ago

Try the pander solution mentioned in: http://stackoverflow.com/questions/25516471/printing-nice-cross-tabulations-in-knitr.