I don't know for sure what result you want, but it may be that using a length(dim(array))-column matrix as your subscript will do what you want. E.g., > a <- array(101:124, dim=4:2) > subscriptMatrix <- cbind(c(1,3), c(2,2), c(2,1)) > subscriptMatrix [,1] [,2] [,3] [1,] 1 2 2 [2,] 3 2 1 > a[subscriptMatrix] [1] 117 107 > a[1, 2, 2] [1] 117 > a[3, 2, 1] [1] 107
Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, May 30, 2015 at 3:29 AM, WRAY NICHOLAS <nicholas.w...@ntlworld.com> 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. > > This is easy if the number of dimensions is fixed for both the array and > the number of elements in the vector (say 4): > > X<-array[vec[1],vec[2],vec[3],vec[4]] > > 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.