This might be a silly question. I am trying to use tbl_summary to create a summary table for my data. But somehow the results for numeric variables are reported as categoricals. I don't know why this happened. Below is the code I used.
test <- data.frame("Gender" = c("Female", "Male", "Female", "Female"),
"vegetable_score" = c(1.214138, 5.552633, 2.757568, 1.209925))
test %>%
tbl_summary(
by = Gender,
type = all_continuous() ~ "continuous",
statistic = list(all_continuous() ~ "{mean} ({sd})")) %>%
modify_header(label ~ "Variable") %>%
modify_spanning_header(c("stat_1", "stat_2") ~ "Gender")
sd(5.552633) evaluates to NA leaving the only statistic available the one shown in the output.
The reprex below uses the built-in trial data set on this code to show that if there are an adequate number of occurrences for each continuous variable by category, it will run.
I tried to increase the number of observations, doesn't seem to solve the problem. What's the minimum number of observations required for each group? Or am I misunderstanding the problem?