我正在使用rstatix
. 我可以为每个变量生成我想要的结果,但无法遍历多个变量以一次性生成一个链接表。
require(dplyr)
require(rstatix)
data <- data.frame(group=rep(c(1,2),5), v1=rnorm(10),v2=rnorm(10))
data %>%
t_test(v1 ~ group,detailed = TRUE) %>%
adjust_pvalue() %>%
add_significance(cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
symbols = c("****", "***", "**", "*", "ns")) %>%
select(c(".y.","estimate1","estimate2","statistic","p.adj","p.adj.signif")) %>%
dplyr::rename(variable = .y.,
'training' = estimate1,
'test' = estimate2,
't-test'=statistic,
p=p.adj,
sl=p.adj.signif)
这失败了:
vars <- c("V1", "V2")
bt <- character(0)
for(i in 1:length(vars)){
bt_temp <- data %>%
t_test(vars[i] ~ group, detailed = TRUE) %>%
adjust_pvalue() %>%
add_significance(cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
symbols = c("****", "***", "**", "*", "ns")) %>%
select(c(".y.","estimate1","estimate2","statistic","p.adj","p.adj.signif")) %>%
dplyr::rename(variable = .y.,
'training' = estimate1,
'test' = estimate2,
't-test'=statistic,
p=p.adj,
sl=p.adj.signif)
bt <- rbind(bt, bt_temp)