1

I'm trying to create descriptive statistics in a "publishable" html format.

Let's take the mtcars data and assume I want to create a table that gives me the usual descriptive statistics for Miles/(US) gallon, Gross horsepower, Weight (1000 lbs), and 1/4 mile time for both automatic and manual cars.

I can get a rough version of what I am looking for by using psych::describeBy

library(tidyverse)
library(psych)

#Descriptive statistics
data("mtcars")

df <- mtcars|>
  select(1,4,6,7,9)

describeBy(df, group = mtcars$am, fast=TRUE)

However, I am trying to create this in a format that is close to what you would find in journal articles and also can be exported as html. Anyone got any suggestions? I tried to use stargazer but struggled to get results for both groups in one table. Thanks!

KSM
  • 11
  • 2

1 Answers1

0

Here is minimal raw data for mtcars grouped by am with gtsummary:

library(tidyverse)
data(mtcars)
as_tibble(mtcars)

library(gtsummary)
mtcars %>% tbl_summary(by = am)

enter image description here

You can have various modifications (labels etc.) in gtsummary.

Marco
  • 2,368
  • 6
  • 22
  • 48