Skip to content
Prev 18573 / 63424 Next

x[1,], x[1,,], x[1,,,], ...

Henrik Bengtsson <hb at maths.lth.se> writes:
I think this should work:

x <- array(1:24, dim=c(3,2,2,2)) # not c(2,2,3,2)....
i <- 2:3
ndim <- length(dim(x))
ix <- as.list(rep(TRUE, ndim))
ix[[1]] <- i
do.call("[", c(list(x), ix))