for循环in如果在r中嵌套for循环

时间:2017-11-15 21:07:59

标签: r

我的循环无法从第三个else if开始工作。

我希望如果该陈述属实,那个位置的Cumu_excess_se2在该位置等于Excess_se并从那里到Cumu_excess_se(t) =Cumu_excess(t-1) + Excess_se(t)

的结尾

我的载体是:

  • Q每小时可提供太阳能电力
  • Excess_se是每小时存储的超额
  • Cumu_excess_se2是多余
  • 的向量和

循环:

for (j in 1:length(Cumu_excess_se)) {
    Cumu_excess_se[j] = sum(Excess_se[1:j])

    se.to.h <- vector("numeric", length(Excess_se))
    for (t in 1:length(se.to.h)) {
        if (Q[t] > maxse) {
            se.to.h[t] = maxse
        } else if ((Q[t] < maxse) & (Cumu_excess_se2[t] == 0)) {
            se.to.h[t] = Q[t]
        } else if ((Q[t] < maxse) & (Cumu_excess_se2[t] >= maxse)) {
            (se.to.h[t] = maxse) & (Cumu_excess_se2[t] = Cumu_excess_se2[t - 1] - (maxse - Q[t]))
        } else if ((Q[t] < maxse) & (Cumu_excess_se2[t] < maxse) & (Cumu_excess_se2[t] > 0)) {
            (se.to.h[t] = Cumu_excess_se2[t]) & (Cumu_excess_se2[t + 1] = Excess_se[t + 1])
        }
    }
}

0 个答案:

没有答案