I would like to subset an array with a dynamic number of dimensions k.
Take the example:
A <- array(1:3^4, dim=c(3,3,3,3))
Because the dimensions can vary (not shown here), I cannot simply define a, b, c, d and make the query via
a <- 1:2; b <- 2; c <- 2:3; d = 1
A[a, b, c, d]
Here has been shown that if one would like to subset only a single element, one can go about it like this:
e <- 1; f <- 2; g <- 3; h <- 1
A[matrix(c(e, f, g, h), nrow = 1)]
This allows me to keep the number of dimensions flexible, but I can only subset single elements, because I cannot represent the sequences a, b, c, d in a matrix.
The desired situation is that I can get the output of
A[a, b, c, d]
without hardcoding the dimensions, i.e. access the array via
A[object]
and the question is basically is this possible and if yes how does 'object' look like.
Any help would be greatly appreciated!