我正在尝试创建一个循环,因此我可以测试多个条件:cond_A、cond_B 和 cond_C,每个条件都针对同一个控件('ctrl')。每个条件和控制由一式三份表示。作为结果,我想获得一个带有条件名称和 pvalues 的数据框。
这是我的输入:
structure(list(ctrl_1 = 1L, ctrl_2 = 2L, ctrl_3 = 3L, cond_A_1 = 4L,
cond_A_2 = 4L, cond_A_3 = 4L, cond_B_1 = 5L, cond_B_2 = 5L,
cond_B_3 = 7L, cond_C_1 = 8L, cond_C_2 = 9L, cond_C_3 = 2L), .Names = c("ctrl_1",
"ctrl_2", "ctrl_3", "cond_A_1", "cond_A_2", "cond_A_3", "cond_B_1",
"cond_B_2", "cond_B_3", "cond_C_1", "cond_C_2", "cond_C_3"), class = "data.frame", row.names = c(NA,
-1L))
以及带有假设 pvalue 的预期输出:
cond_A_pval cond_B_pval cond_C_pval
0.05 0.9 0.006
这是我的出发点:
pval<-apply(df,1,function(x) {t.test(x[1:3],x[4:6])$p.value})