我尝试使用tbl_summary()
创建一个包含列总和的表(正确测试分数和错误测试分数的总和),但是它似乎一直将我的连续变量视为分类变量?
我尝试将类型指定为continuous,但没有成功。
我的目标是:
library(gtsummary)
library(tidyverse)
test <- data.frame("With_assistant" = c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE),
"correct_answers" = c(2,4,5,6,1,2,7,2,1,2,3),
"incorrect_answers" = c(1,2,1,5,3,1,2,5,3,2,4))
output <- test %>%
group_by(With_assistant) %>%
summarize(
total_correct=sum(correct_answers, na.rm=TRUE),
total_incorrect=(sum(incorrect_answers, na.rm=TRUE))
)
output
Table_1
我尝试了以下方法:
library(gtsummary)
library(tidyverse)
test <- data.frame("With_assistant" = c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE),
"correct_answers" = c(2,4,5,6,1,2,7,2,1,2,3),
"incorrect_answers" = c(1,2,1,5,3,1,2,5,3,2,4))
output <- test %>%
tbl_summary(
by = With_assistant,
statistic = all_continuous() ~ {n}
)
生成每个结果的计数,如下所示:
Table_2
library(gtsummary)
library(tidyverse)
test <- data.frame("With_assistant" = c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE),
"correct_answers" = c(2,4,5,6,1,2,7,2,1,2,3),
"incorrect_answers" = c(1,2,1,5,3,1,2,5,3,2,4))
output <- test %>%
tbl_summary(
by = With_assistant,
type = c(correct_answers, incorrect_answers) ~ "continuous",
statistic = all_continuous() ~ {n},
percent = "column",
missing = "no"
) %>%
print(output)
产生错误“* 错误:处理元素“Anatomy_yes”的statistic
参数时出错。传递的值应为字符。*”
1条答案
按热度按时间qni6mghb1#
您几乎成功了。再次查看文档。
type
选项,因为小于10的数值的默认值是分类的。这就是你想达到的目标吗?
使用
statistic
选项,为总和指定: