My loop is not working from the third else if
.
I want that if that statement is true that Cumu_excess_se2
at that position is equal Excess_se
at that position and from there to the end that Cumu_excess_se(t) =Cumu_excess(t-1) + Excess_se(t)
My vectors are:
Q
is solar electricity available hourlyExcess_se
is the excess to store per hourCumu_excess_se2
is the vector sum of the excess
The loop:
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])
}
}
}