Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To use the qwraps2 function to analyze data that includes nested groups, you can use the :: operator to specify the levels of the groups, and then use the by argument to group and summarize the data at each level. For example:

library(qwraps2)

# Example data with nested groups
data <- data.frame(
  region = c(rep("North", 6), rep("South", 6)),
  state = c(rep("NY", 3), rep("PA", 3), rep("TX", 3), rep("FL", 3)),
  sales = c(100, 150, 200, 75, 125, 175, 250, 300, 350, 225, 275, 325)
)

# Create a qwraps2 table with nested grouping by region and state
table1 <- qwraps2::summary_table(
  data = data,
  vars = c(sales),
  by = list(region::state),
  treatment = NULL,
  statistic = "mean_sd_n",
  missing = TRUE,
  digits = 2,
  report = TRUE
)

table1

This will create a summary table with mean, standard deviation, and sample size for sales at each level of the nested groups (e.g., mean sales for North NY, South PA, etc.).