rsummarytools

Is there a way to display multiple tables in the RStudio Viewer?


If I run the following crosstab code, using the ctable function from the summarytools package:

library(summarytools)
data(mtcars)
varlist <- names(mtcars[,3:5])
crosstables <- list(NULL)
for (i in varlist){
  crosstables[[i]] <- ctable(mtcars[[i]], mtcars$cyl, prop = 'r', style="simple", method = "render", header=TRUE)
  view(crosstables[[i]])
  }

instead of seeing three crosstab tables in the RStudio viewer only the last one is displayed. If I attempt to display all three tables:

view(crosstables)

I get the following error message:

x must either be a summarytools object created with freq(), descr(), or a list of freq() / descr() objects created using by(), or a list of freq() objects created using lapply(). Support for by() used with ctable() may be available in future realeases.

Is there a way to stack all three tables in the same viewer window? Maybe a way to combine the html output files for the crosstabs?


Solution

  • you can change view to print and knit to html

    It's the same code:

    library(summarytools)
    data(mtcars)
    varlist <- names(mtcars[,3:5])
    crosstables <- list(NULL)
    for (i in varlist){
      crosstables[[i]] <- ctable(mtcars[[i]], mtcars$cyl, prop = 'r', style="simple", method = "render", header=TRUE)
      print(crosstables[[i]])
      }
    

    Only the last line is different. And then use RStudio's knitting feature:

    enter image description here