Skip to content

Instantly share code, notes, and snippets.

@jmcastagnetto
Last active August 29, 2015 13:57
Show Gist options
  • Save jmcastagnetto/9769367 to your computer and use it in GitHub Desktop.
Save jmcastagnetto/9769367 to your computer and use it in GitHub Desktop.
Code that illustrates the sj.xtab() bug when rendering to HTML with knitr (ref: https://github.com/sjPlot/devel/issues/1)
# bug in sjt.xtab()
```{r}
require(sjPlot)
set.seed(12345)
var1 <- as.factor(sample(c("ok", "not ok"), 1000, replace=TRUE, prob=c(0.2, 0.8)))
var2 <- as.factor(sample(c("foo", "bar", "boing", "kaboom", "plonk"), 1000, replace=TRUE))
var3 <- sample(2:20, 1000, replace=TRUE)
xtab1 <- sjt.xtab(var2, var3, var1, variableLabels=c("var2", "var3", "var1"),
showSummary=FALSE, showLegend=FALSE, no.output=TRUE)
```
## Table made using sjt.xtab()
`r xtab1$knitr`
## Output of xtabs()
```{r}
xtabs( ~ var2 + var3 + var1)
```
@jmcastagnetto
Copy link
Author

This bug has been fixed by the sjPlot author in version 1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment