0

I'm relatively new to Rmarkdown and would like to create a report with two tables side by side.

There are numerous references on how to do this using kable, knitr and mini.pages, and a few references include: Align Multi Tables Side by Side , Split Table Side by Side , Knitr Github. There are a few others on SO.

What I am doing: I have a data frame where I'm running some basic statistics. I would like to report these stats in two basic summary tables side by side. The code below is what I believe is the best to do this, but when I knit the report I just get the code returned and no tables.

 ```{r message=FALSE,include=FALSE, warning=FALSE,message=FALSE}

       dep<-dep%>%filter(tier !=0)
       d<-dep%>%dplyr::group_by(Level)%>%
       dplyr::summarise(Count=n(),
        `MeanBalance`=mean(Bal),
        `MedianBalance`=median(Bal),
        `MaxBalance`=max(Bal),
        `MinBalance`=min(Bal),
        `1stQuantBalance`=quantile(Bal,probs=.25,type = 1),
        `3rdQuantBalance`=quantile(Bal,probs=.75,type = 3),
        `MeanRate`=mean(HR),
        `MedianRate`=median(HR),
        `MaxRate`=max(HR),
        `MinRate`=min(HR),
        `1stQuantRate`=quantile(HR,probs=.25,type = 1),
        `3rdQuantRate`=quantile(HR,probs=.75,type = 3))%>%
        mutate_each(funs(prettyNum(., big.mark=",",scientific=FALSE)))


   `````

   ```{r sample, echo=FALSE, results='asis'}

   t1 <- kable(head(d)[1:6], format = "latex", booktabs = TRUE)
   t2 <- kable(head(d)[7:12], format = "latex", booktabs = TRUE)

   cat(c("\\begin{table}[!htb]
\\begin{minipage}{.5\\linewidth}
  \\caption{}
  \\centering",
    t1,
"\\end{minipage}%
\\begin{minipage}{.5\\linewidth}
  \\centering
    \\caption{}",
    t2,
"\\end{minipage} 
\\end{table}"
 ))  
``````

I have also tried just using Grobtable function, but this just overlaps the tables.

Any help would be much appreciated.

*Update Below for a sample of 2 cols.

d<-structure(list(Level=c(rep(1:7)),MeanBalance=c(seq(100,500,length.out = 7)),MedianBalance=c(seq(.003,.9,length.out = 7))))
a_js12
  • 329
  • 1
  • 8
  • 1
    Can you add a sample of data so we can recreate this? Ideally the sample doesn't have to have all your columns, just `dput` on some subset of `d` – camille Feb 06 '20 at 16:31
  • I just added something I hope will be enough thanks – a_js12 Feb 06 '20 at 16:55

0 Answers0