Although I have searched for, I could not find a straightforward answer to my question. Suppose I have an array:
vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
result <- array(c(vector1,vector2),dim = c(3,3,2))
Now, I want to subset this array in such a way as to get elements from certain rows and columns. For example:
result[1,3,1:2]
result[3,1,1:2]
since I have many indices, they are sotred in
rowind=c(1,3)
colind=c(3,1)
For subsetting, I have tried to use vectors of rows and columns in this way
dim(result[rowind,colind,1:2])
[1] 2 2 2
This is not what I want. I want my output to be one value for each pair of the indices. In fact, I want my extracted matrix to have a dimension of 2x2 (not 2x2x2). To let you know I have tried "loop".But the problem is that I have many numbers of arrays and it would be very time-consuming.
result_c=matrix(NA,nrow=2,ncol=2)
for (i in 1:2){
result_c[i,]=result[rowind[i],colind[i],]
}
Thanks for your help.