0

I am generating figures and reports using RMarkdown in .html format. I now wish to create three separate tables in the .html document but am unsure if I can create these. My data.frame consists of call logs, by differing locations and service roles. The amount of time (duration, in minutes) is also recorded. However, I have data on many workers so wish to subset by each worker's ID.

Can I create a row of three (subset, different data.frames) like this one in Excel?

enter image description here

My data.set is sensitive, so here is an example using R's inbuilt datasets and my RMarkdown code.

---
title: <center> <h1>Call Centre Report</h1> </center>
output:
 html_document
---

```{r echo=FALSE}
library("htmlTable")
htmlTable(subset(mtcars, gear=="4"),
          header =  paste(c("mpg", "cyl",
                            "disp", "hp", "drat",
                            "wt", "qsec", "vs", "am", "gear", "carb")))
```

```{r echo=FALSE}
library("htmlTable")
htmlTable(subset(iris, Species=="setosa"),
          align="rrrr|r",
          header =  paste(c("Sepal Length", "Sepal Width",
                            "Petal Length", "Petal Width", "Species")))
```

```{r echo=FALSE}
library("htmlTable")
htmlTable(subset(chickwts, feed=="horsebean"),
          align="r|r",
          header =  paste(c("Weight", "Feed")))
```

Thank you.

user2716568
  • 1,866
  • 3
  • 23
  • 38
  • 1
    [Please provide a minimal, complete and verifiable example](http://stackoverflow.com/help/mcve). – Therkel Apr 02 '17 at 11:27
  • You can subset a table in RMarkdown the same way you'd subset a table in R generally. There are several ways to subset so you just need to pick one that works best for you. – Ryan Morton Apr 03 '17 at 14:38
  • The subset issue is addressed and I have included an example. Please see my updated question regarding the multiple but aligned tables. – user2716568 Apr 14 '17 at 02:47
  • So this question is about side-by-side tables in Rmarkdown, not `subset`, right? Perhaps you should change the subject. – r2evans Apr 14 '17 at 03:32
  • Thank you, title is edited. – user2716568 Apr 14 '17 at 03:34
  • 2
    I know it is not `htmlTable`, but if you are willing to go with other table-formatting functions, perhaps this would help: http://stackoverflow.com/questions/38036680/align-multiple-tables-side-by-side – r2evans Apr 14 '17 at 15:39

1 Answers1

2

You can create a div element with the following style <div style="display:flex; justify-content: space-between;">

---
title: <center> <h1>Call Centre Report</h1> </center>
output:
 html_document
---
<div style="display:flex; justify-content: space-between;">
```{r echo=FALSE}
library("htmlTable")
htmlTable(subset(mtcars, gear=="4"),
          rnames = FALSE,
          header =  paste(c("mpg", "cyl",
                            "disp", "hp", "drat",
                            "wt", "qsec", "vs", "am", "gear", "carb")))
```

```{r echo=FALSE}
library("htmlTable")
htmlTable(subset(iris, Species=="setosa"),
          align="rrrr|r",
          rnames = FALSE,
          header =  paste(c("Sepal Length", "Sepal Width",
                            "Petal Length", "Petal Width", "Species")))
```
```{r echo=FALSE}
library("htmlTable")
htmlTable(subset(chickwts, feed=="horsebean"),
          rnames = FALSE,
          align="r|r",
           header =  paste(c("Weight", "Feed")))
```
</div>
Marcelo
  • 4,234
  • 1
  • 18
  • 18