rsummaryqwraps2

How to create a table with summary_table (qwraps2) in R for several data frames having the same variables?


I'm trying to find a way how to use function summary_table (qwraps2) for several data frames having the same variables. So that I end up having a column for each data.frame.

This is similar to what I got so far (example from https://www.rdocumentation.org/packages/qwraps2/versions/0.5.0/topics/summary_table):

libary(qwraps2)
our_summary1 <-
  list("Miles Per Gallon" =
       list("min"       = ~ min(mpg),
            "max"       = ~ max(mpg),
            "mean (sd)" = ~ qwraps2::mean_sd(mpg)),
       "Displacement" =
       list("min"       = ~ min(disp),
            "median"    = ~ median(disp),
            "max"       = ~ max(disp),
            "mean (sd)" = ~ qwraps2::mean_sd(disp)),
       "Weight (1000 lbs)" =
       list("min"       = ~ min(wt),
            "max"       = ~ max(wt),
            "mean (sd)" = ~ qwraps2::mean_sd(wt)),
       "Forward Gears" =
       list("Three" = ~ qwraps2::n_perc0(gear == 3),
            "Four"  = ~ qwraps2::n_perc0(gear == 4),
            "Five"  = ~ qwraps2::n_perc0(gear == 5))
       )

orig_opt <- options()$qwraps2_markup
options(qwraps2_markup = "markdown")

whole <- summary_table(mtcars2, our_summary1)
whole

But how to get a second, third data.frame in there?

I tried something like:

mtcars2.copy<-data.frame(mtcars2)
whole_table= summary_table(c(mtcars2,mtcars2.copy), our_summary1)
```
But it didn't work...

Solution

  • Ok, I think I found a solution:

    whole_table= summary_table(mtcars2, our_summary1)
    whole_table2= summary_table(mtcars3, our_summary1)
    
    cbind(whole_table,whole_table2)