[R] Arrays of variable dimensionality
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat May 30 13:30:27 CEST 2015
On 30/05/2015 11:29, WRAY NICHOLAS wrote:
> Hello folks
> Supposing I have a multidimensional array in an R prog, say a 4D array.
> I want the coordinate quantities to be read off from a vector. The values
> in the vector (vec) are generated by a function.
It is not clear what you want to do.
> This is easy if the number of dimensions is fixed for both the array and
> the number of elements in the vector (say 4):
Is 'array' an array and not the function of that name?
I am guess you are missing do.call, the way to generate calls with
variable-length argument lists. My guess of your intention could be written
arr <- array(1:256, rep(4,4))
vec <- 1:4
arr[1, 2, 3, 4] # same as
do.call(`[`, c(list(arr), as.list(vec)))
> But if the number of dimensions of the array is not fixed and can change
> during the course of the prog I am stuck as to how to do this, as I don’t
> know a way of feeding a vector or list of unspecified beforehand length
> into the coordinates for an array
> I can’t find anything useful about this on the net
> Does anyone have any ideas?
> Thanks, Nick
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK
More information about the R-help