r - Two way frequency table in Rmarkdown -


in way can construct two-way frequency table in rmarkdown? like:

this

i tried use both kable function knitr package , datable function dt package, none gave me desired result.

update: reproducible code 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     b   c              1 118  98 106              2 106  95 121              3 128 114 114 

i want 'vertical_title' , 'horizontal_title' visible table in rmarkdown.

you can construct table follows:

--- title: example 1 output: pdf_document ---  ### test  ```{r,results='asis',echo=false}  library(xtable) <- 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) df <- as.data.frame.matrix(table(df))    print(xtable(df,             align = "|l|rrr|",             caption = "test"),       caption.placement = 'top',       comment = f,       scalebox=1,       include.rownames = t,       hline.after = c(-1,0,nrow(df)),       vline.after = c(1),       format.args=list(big.mark = ",", decimal.mark = "."))   ``` 

see here way add multicolumn , multirows titles:

r package xtable, how create latextable multiple rows , columns r

hope helps!


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -