I am trying to make a table with summary statistics that looks similar to this (but with min/max/median/mean values filled in):
Type
Mass (g) tct tcx tht thx tct
Min
Max
Median
Mean (SD)
Length (mm)
Min
Max
Median
Mean (SD)
Width (mm)
Min
Max
Median
Mean (SD)
Or even like this: (with a width column too)
Mass (g) Length (mm)
Type Min Max Median Mean (SD) Min Max Median Mean (SD)
tct
tcx
tht
thx
tct
Here is an example of my data:
dat <- data.frame(
"id" = c(01,02,03,04,05,06,07,08,09,10),
"type" = c("tct", "tcx", "tht", "thx", "tct"),
"mass" = c(0.03,0.01,0.04,0.06,0.07,0.03,0.03,0.01,0.04,0.02),
"size.length" = c(8,6,5,6.5,5,5.5,6,7,4,3),
"size.width" = c(2,4,3,4,5,6,3,4,2,1),
)
This is the code I am working on, taken from here.
library(qwraps2)
summary <-
list("Mass (g)" =
list(
"Min" = ~ min(.data$mass.g),
"Max" = ~ max(.data$mass.g),
"Median" = ~ median(.data$mass.g)
"Mean (SD)" = ~ qwraps2::mean_sd(.data$mass.g)),
"Length (mm)" =
list(
"Min" = ~ min(.data$size.length),
"Max" = ~ median(.data$size.length),
"Median" = ~ max(.data$size.length),
"Mean (SD)" = ~ qwraps2::mean_sd(.data$size.length)),
"Width (mm)" =
list(
"Min" = ~ min(.data$size.width),
"Max" = ~ median(.data$size.width),
"Median" = ~ max(.data$size.width),
"Mean (SD)" = ~ qwraps2::mean_sd(.data$size.width)
))
summary
by_type <- summary_table(dplyr::group_by(plastics, type), summary)
by_type
But I keep getting the error message: "Error: x
must be a formula"
My end goal is to complete a table that resembles the above and export it as an excel file or word doc.
Any help would be appreciated.