Reputation: 97
Let's say I have an array given by
A = array(1:8,c(2,2,2))
ind = which(A[,,1]>=2)
which yields
[1] 2 3 4
Now, how do I access the 2,3,4
values at each level in the third dimension (so, 2,3,4,6,7,8), but not 5?
A[ind,]
obviously doesn't work...
Upvotes: 0
Views: 47
Reputation: 2070
ind = which(A[,,c(1,2)]>=2,arr.ind=T)
A[ind]
EDIT
Get the index of one array from a multidimensional array:
A = array(1:8,c(2,2,2))
ind = which(A[,,1]>=2,arr.ind=T)
apply(A, 3, function(x) x[ind])
Upvotes: 1