I have the following dummy data.frame
set.seed(12345)
df<-data.frame(var1=floor(runif(10,1000000,5000000)), group=rep(c("A","B"),5), event=rep(c("Yes","No"),5))
And would like to create a summary table of it. I tried to use qwraps2
As follows:
summary<-list("VAlue1" =
list("min" = ~ min(.data$var1),
"max" = ~ max(.data$var1),
"mean (sd)" = ~ qwraps2::mean_sd(.data$var1)),
"Group" =
list("Yes" = ~ qwraps2::n_perc0(.data$group == "A"),
"No" = ~ qwraps2::n_perc0(.data$group == "B")))
knitr::kable(
qwraps2::summary_table(dplyr::group_by(df, event),summary )
)
The output is unfortunately missing the variable to look at:
| |event: No (N = 5) |event: Yes (N = 5) |
|:---------|:--------------------------------|:----------------------------------|
|min |2591303 |1315253 |
|max |4232714 |4711820 |
|mean (sd) |3,456,579.40 ± 672,665.35 |3,029,844.00 ± 1,572,709.32 |
|Yes |0 (0) |5 (100) |
|No |5 (100) |0 (0) |
How do I incorporate the category "Value1" and "Group"?
Thank you!
suggestions for other packages are welcome, too.
The object returned by
summary_tableis a character matrix with the additional S3 classqwraps2_summary_table. The rowgroup namesValue1andGroupare not part of the character matrix explicitly, they are part attributes. The print method for theqwraps2_summary_tableobject builds the table as need for the appropriate markup language, LaTeX or markdown.Two edits the the example posted to get the table you are looking for:
Add
options(qwraps2_markup = "markdown")to your script. The default mark up language is LaTeX, setting this option changes the default to markdown.Do not wrap
summary_tableinside ofknitr::kable: this prevents the needed print method from being called.Created on 2020-09-15 by the reprex package (v0.3.0)