一般化しようとしました。
# example values
k <- 3 # dim=c(n1, n2, ..., nk)
n1 <- 5; n2 <- 6; n3 <- 4; p <- 5
set.seed(1); values <- array(sample(n1*n2*n3*p), dim = c(n1, n2, n3, p))
set.seed(1); indices <- array(sample(p, n1*n2*n3, replace = T), dim = c(n1, n2, n3))
# do +1 to last dim and put indices into it (to enable apply() to get both information).
values2 <- array(values, dim=c(n1, n2, n3, p+1))
values2[,,,p+1] <- indices
values[1,1,1,] # [1] 160 477 111 27 569
indices[1,1,1] # [1] 2
values2[1,1,1,] # [1] 160 477 111 27 569 2 # last values is index (value2[1,1,1,p+1])
values2[1,1,1,][values2[1,1,1,p+1]] # 477
# using apply(), get the values with all combination of n1, ..., nk
slice2 <- apply(values2, 1:k, function(x) x[x[p+1]])
# check just to be sure
slice <- array(NA, dim = c(n1, n2, n3))
for(a in 1:n1) for(b in 1:n2) for(c in 1:n3) {
slice[a, b, c] <- values[a, b, c, indices[a, b, c]] }
identical(slice, slice2) # [1] TRUE # no problem
サンプルデータと予想出力を含めてください – HubertL