I am working on some data in R that consist of four-dimensional arrays composed of three spatial dimensions and a time dimension: x, y, z, t. For some of my analyses, I woul
Accessing by each dimension individually does not work as @tilo-wiklund or I expect. Instead of 23 rows across 10 time steps, the result is a 23x23x23 cube across the 10 time steps.
r.idvdim <- a4d[indices[,1],indices[,2],indices[,3],]
r.apply <- apply(a4d, 4, `[`, indices)
r.cbind <- matrix(a4d[lookup],ncol=nt)
dim(r.idvdim) # [1] 23 23 23 10
dim(r.apply) # [1] 23 10
dim(r.cbind) # [1] 23 10