I am using gtsummary package to tabulate my regression results.
With difficulty, I have tried to give my table a spanning header using the following function modify_spanning_header(starts_with("stat_") ~ "**Logistic regression for years in US states**")
.
When I use this function along with the code below, I get the following response:
Error: Can't join on `x$column` x `y$column` because of incompatible types.
ℹ `x$column` is of type <character>>.
ℹ `y$column` is of type <integer>>.
Any idea what this could be? The full code which includes dummy data and packages is as follows:
# load packages
library(gtsummary)
# dummy data
crime <-data.frame(State = sample(c("SF", "AR", "NYC","MN"),13000,replace = TRUE),
Year = sample(as.factor(c(1990, 2000)),13000, replace = TRUE)
)
# logistic model with visual
glm(Year ~ State, data = crime, family = binomial) %>%
tbl_regression(exponentiate = TRUE)
I am trying to follow and reproduce example two in this vignette - see here.
This issue you're experiencing is that you're selecting all columns that begin with
"stat_"
. But in atbl_regression()
table, there are no columns that begin with"stat_"
. Use the helper functionshow_header_names()
to print the current column names along with their headers. This will help guide you to select the appropriate columns. Example below.Created on 2020-10-21 by the reprex package (v0.3.0)