R:为什么即使没有循环,if语句也要求值两次?

R:为什么即使没有循环,if语句也要求值两次?,r,if-statement,R,If Statement,我知道关于if语句已经有很多问题了,但由于它们几乎都包含循环,我还没有找到合适的答案 我用3个测试中最重要的统计值(p值,Cohen's d,…)构建了一个数据框架: p1 = 0.9 p2 = 0.00021 p3 = 0.001 stat <- data.frame(ID=c("Group A","Group B","Group C"),pvalues = c(p1,p2,p3),cohensd=c(0.14,0.5,0.2)

我知道关于if语句已经有很多问题了,但由于它们几乎都包含循环,我还没有找到合适的答案

我用3个测试中最重要的统计值(p值,Cohen's d,…)构建了一个数据框架:

p1 = 0.9
p2 = 0.00021
p3 = 0.001
stat <- data.frame(ID=c("Group A","Group B","Group C"),pvalues = c(p1,p2,p3),cohensd=c(0.14,0.5,0.2))
p1=0.9
p2=0.00021
p3=0.001
stat
stat$ID[which.max(stat$cohensd)&stat$pvalues
stat$ID[which.max(stat$cohensd)&stat$pvalues
if(((p1 < 0.05)+(p2 < 0.05) + (p3 < 0.05))>=2 ){paste("The effect is strongest for", stat$ID[which.max(stat$cohensd)&stat$pvalues<0.05])}
if(((p1 < 0.05)+(p2 < 0.05) + (p3 < 0.05))>=2 ){paste("The effect is strongest for", stat$ID[which(stat$cohensd &stat$pvalues<0.05)[1]])}

#[1] "The effect is strongest for Group B"