Two way frequency table in Rmarkdown

Viewed 4551

In what way can I construct a two-way frequency table in Rmarkdown? Something like:

this

I tried to use both the kable function from the knitr package and the datable function from the DT package, but none gave me the desired result.

Update: Reproducible code with example.

a <- sample(x = c(1,2,3), size = 1000, replace = T)
b <- sample(x = c('a', 'b', 'c'), size = 1000, replace = T)

df <- data.frame(vertical_title = a, horitzontal_title = b)

table(df)

              horitzontal_title
vertical_title   a   b   c
             1 118  98 106
             2 106  95 121
             3 128 114 114

I want 'vertical_title' and 'horizontal_title' to be visible for my table in Rmarkdown.

1 Answers
Related