1

Trying to simply produce separate tables of Anscombe's Quartet Sets, so that there is a nice space between them and formatting. I'd prefer a 1x4 set of tables, but a 2x2 would suffice.

For either dimension of results, both knitr::kables and stargazer solutions do not seem to be able to handle multiple non-model or non-summary objects:

anscombe.1 <- data.frame(X1 = anscombe[["x1"]], Y1 = anscombe[["y1"]], Set = "1")
anscombe.2 <- data.frame(X2 = anscombe[["x2"]], Y2 = anscombe[["y2"]], Set = "2")
anscombe.3 <- data.frame(X3 = anscombe[["x3"]], Y3 = anscombe[["y3"]], Set = "3")
anscombe.4 <- data.frame(X4 = anscombe[["x4"]], Y5 = anscombe[["y4"]], Set = "4")
# I usually call stargazer() with multiple model objects, so...
stargazer(anscombe.1, anscombe.2, anscombe.3, anscombe.4, summary = FALSE)

Error in if (.global.summary[i] == TRUE) { : missing value where TRUE/FALSE needed
Calls: ... withVisible -> eval -> eval -> stargazer -> .stargazer.wrap

If call stargazer(anscombe.1, summary = FALSE), however, I get the desired output. Similarly, I can call knitr::kable(anscombe) and get the table for a single set, but not all four:

knitr::kable(anscombe.1, anscombe.2, anscombe.3, anscombe.4)

Quitting from lines 9-36 (anscombe.Rmd) Error in round(x[, j], digits[j]) :
non-numeric argument to mathematical function Calls: ... withCallingHandlers -> withVisible -> eval -> eval ->

How can I put these four sets together - preferably in a single row of four tables, with some space between them - so that I can line up their (similar) summary statistics below, likely using the same technique for a columnar summary?

Thomas
  • 43,637
  • 12
  • 109
  • 140
d8aninja
  • 3,233
  • 4
  • 36
  • 60
  • 1
    You are really unclear about what kind of output you want. Are you using knitr or Sweave? Are you producing LaTeX or Markdown? Nobody can answer your question without those details. – user2554330 Oct 30 '16 at 16:30
  • This may be what you are looking for [Align two data.frames next to each other with knitr?](http://stackoverflow.com/questions/17717323/align-two-data-frames-next-to-each-other-with-knitr). But I agree with @user2554330. It makes a difference whether you want to knit it to html or to latex. – acylam Oct 30 '16 at 20:58
  • @user2554330 I am compiling this in an rmd file with the doc_type set to pdf_document; so I am trying to knit latex using a call to stargazer or kable – d8aninja Oct 31 '16 at 15:27
  • @useR see my comment above – d8aninja Oct 31 '16 at 15:27

1 Answers1

3

Putting things side-by-side in Markdown is hard: it's not designed for that. So you need to include some LaTeX markup in the file.

For example,

---
title: "Side by Side"
date: "October 31, 2016"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Side by Side

\begin{minipage}{0.3\textwidth}
```{r}
knitr::kable(diag(2), format = "latex")
```
\end{minipage}
\begin{minipage}{0.3\textwidth}
```{r}
knitr::kable(diag(3), format = "latex")
```
\end{minipage}
\begin{minipage}{0.3\textwidth}
```{r echo=FALSE}
knitr::kable(diag(4), format = "latex")
```
\end{minipage}

This produces output like

enter image description here

user2554330
  • 37,248
  • 4
  • 43
  • 90