我正在尝试按组创建一系列表,并且我希望每个表使用不同的变量迭代运行。我还想将 anova 的 p 值添加到表的底部。我可以使用 aov 函数和 kable 函数轻松地做一个表。我认为 for 循环可能如下工作:
#list of column names
varlist <- c("var1", "var2", "var3", "var4", "var5", "var6")
for (var in 1:6){
#anova
aov(varlist[[var]] ~ group, data=dc3)
#pull out pvalue for anova as string
pval <-paste("ANOVA P-Value:", round(summary(fit)[[1]][["Pr(>F)"]][[1]], 3))
# Create Table
Table <- dc3 %>% group_by(group) %>%
summarise(Mean = round(mean(varlist[[var]], na.rm = TRUE),2), SD = round(sd(varlist[[var]], na.rm = TRUE),2))
# Add Pvalue to bottom on table
kable(worst_arr_delays, "html") %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>%
add_footnote(c(pval2), notation = "symbol")
}
理想情况下,这会给我六个看起来与此类似的表: