Question

I am using R markdown with sjPlot package to produce some reports. I already know how to print a sjt.df() table in a inline chunk. But I want to put a sjt.df() in a multiline chunk inside a for statement, like this:

```{r eval=T}
library(sjPlot)

data(efc)

db <- efc[1:30,1:5]
for(i in unique(db$e15relat)) {
 db2 <- subset(db, db$e15relat == i, 1:3)
 sjt.df(db2, title = "Title X", stringVariable="N", alternateRowColors=TRUE,
 describe=FALSE, encoding = "UTF-8", no.output=TRUE)$knitr
}
```

When it runs, we got only percentage. Any idea?

Was it helpful?

Solution

Based on this page http://strengejacke.wordpress.com/2014/03/04/beautiful-table-outputs-in-r-part-2-rstats-sjplot under "knitr integration," it seems to imply that only an in-line code snip will work. I'm not completely sure, but this worked for me:

```{r, eval = TRUE, results = 'hide'}
library(sjPlot)

data(efc)
list1 <- list()
db <- efc[1:30,1:5]
for(i in unique(db$e15relat)) {
 db2 <- subset(db, db$e15relat == i, 1:3)
 list1[[i]] <- sjt.df(db2, title = "Title X", stringVariable="N", 
                      alternateRowColors=TRUE, useViewer = F,describe=FALSE,
                      encoding = "UTF-8", no.output=TRUE)$knitr
}
```

### Table 1:
`r list1[[1]]`

### Table 2:
`r list1[[2]]`

OTHER TIPS

Since this is a frequently asked question I get via mail, I've setup an online documentation at http://www.strengejacke.de/sjPlot/

For the basics of table output functions see http://www.strengejacke.de/sjPlot/sjtbasics/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top