Hey,
I am a beginner in R and have some challenges in filling of 3D array.
Data:
fkt.P=function(P,L) {
X.Re=numeric(length(S.1))
for(i in 1:length(S.1)){
X.Re[i]=min(max(S.1[i]-P,0),L)}
pi.s=mean(S.1)*(1+load.S)
pi.re=mean(X.Re)*(1+load.Re)
A.0=EC.0+pi.s-pi.re
alpha.rf=0.6
alpha.DB=0.5*(1-alpha.rf)
alpha.BMW=1-alpha.rf-alpha.DB
A.1=A.0*exp(alpha.DB*r.DB+alpha.BMW*r.BMW+alpha.rf*rf
RBC.1=A.1-S.1+X.Re
SP.1=numeric(length(RBC.1))
for( i in 1:length(RBC.1)){
if(RBC.1[i]<0)
{SP.1[i]=1}
else{SP.1[i]=0}
}
and so on.......
return(c(RBC.1, SP.1, and other variables))
}
P_seq=seq(0,300,100)
L_seq=seq(0,200,100)
res=array(c(0,0), dim=c(length(P_seq),7,length(L_seq))) #emty array with nrow=length(P_seq), #ncol=7, #number of matrices =length(L_seq)
I have to fill the empty array with information (by rows for each matrix)
My Idea:
for (k in 1:length(P_seq)){for (j in 1:length(L_seq)) {res[k,,j] = fkt.P(P_seq[k],L_seq[j])}}
Result: I have the same numbers in first matrix.
What could be the problem? Thank you in advance.