I want to make a multi-dimensional array. To be specific I want to make the
following array
results<-array(0,dim=c(2,2,64,7))
This is the code I have created but it gives no result due to the error
"subscript out of bound".
x<-rep(7,7) # Missingness in intervention
y<-rep(7,7) # Missingness in control
arraynames<-list(Group=c("Success","Failure"),Outcome=c("Intervention","Control"),Trial=c("1":"7"))
mat.stat<-array(c(9,16,10,15,66,12,44,23,102,88,66,104,277,60,247,119,23,43,20,41,201,162,122,
263,14,41,4,41),dim=c(2,2,7),dimnames=arraynames);mat.stat
Nx<-rep(0,length(x))
Ny<-rep(0,length(y))
n<-(x+1)*(y+1)
results<-array(0,dim=c(2,2,64,7))
l<-1
for(i in 1:length(x)){
Nx[i] <- length(1:(x[i]+1))
Ny[i] <- length(1:(y[i]+1))
for(j in 1:(Nx[i])){
for(k in 1:(Ny[i])){
results[,,l,i]<-mat.stat[,,i]+matrix(c(c(0:x[i])[j],c(0:y[i])[k],-c(0:x[i])[j],
-c(0:y[i])[k]),nrow=2,ncol=2,byrow=T)
l<-l+1
}
}
}
results
Any suggestion would be really welcome!
Thank you very much!
Loukia
[[alternative HTML version deleted]]