Re: [R] function to find coodinates in an array

2007-08-17 Thread Martin Maechler
> "GaGr" == Gabor Grothendieck <[EMAIL PROTECTED]> > on Thu, 16 Aug 2007 23:46:28 -0400 writes: GaGr> Get the indices using expand.grid and then reorder GaGr> them: set.seed(1); X <- array(rnorm(24), 2:4) # input GaGr> X # look at X GaGr> do.call(expand.grid, sapply(di

Re: [R] function to find coodinates in an array

2007-08-16 Thread Gabor Grothendieck
Get the indices using expand.grid and then reorder them: set.seed(1); X <- array(rnorm(24), 2:4) # input X # look at X do.call(expand.grid, sapply(dim(X), seq))[order(X),] On 8/16/07, Ana Conesa <[EMAIL PROTECTED]> wrote: > Dear list, > > I am looking for a function/way to get the array coordin

Re: [R] function to find coodinates in an array

2007-08-16 Thread François Pinard
[Ana Conesa] > I am looking for a function/way to get the array coordinates of given > elements in an array. What I mean is the following: > - Let X be a 3D array > - I find the ordering of the elements of X by ord <- order(X) > (this returns me a vector) > - I now want to find the x,y,z coordin

Re: [R] function to find coodinates in an array

2007-08-16 Thread Marc Schwartz
If I am correctly understanding the problem, I think that this is what you want: set.seed(1) # Create a 3x3x3 array ARR <- array(sample(100, 27), c(3, 3, 3)) > ARR , , 1 [,1] [,2] [,3] [1,] 27 89 97 [2,] 37 20 62 [3,] 57 86 58 , , 2 [,1] [,2] [,3] [1,]6 61

Re: [R] function to find coodinates in an array

2007-08-16 Thread Henrik Bengtsson
See arrayIndex() in the R.utils package, e.g. X <- array((2*3*4):1, dim=c(2,3,4)) idx <- 1:length(X) ijk <- arrayIndex(idx, dim=dim(X)) print(ijk) [,1] [,2] [,3] [1,]111 [2,]211 [3,]121 [4,]221 [5,]131 [6,]231 [7,]1

Re: [R] function to find coodinates in an array

2007-08-16 Thread Moshe Olshansky
A not very good solution is as below: If your array's dimensions were KxMxN and the "linear" index is i then n <- ceiling(i/(K*M)) i1 <- i - (n-1)*(K*M) m <- ceiling(i1/K) k <- i1 - (m-1)*K and your index is (k,m,n) I am almost sure that there is a function in R which does this (it exists in Mat

[R] function to find coodinates in an array

2007-08-16 Thread Ana Conesa
Dear list, I am looking for a function/way to get the array coordinates of given elements in an array. What I mean is the following: - Let X be a 3D array - I find the ordering of the elements of X by ord <- order(X) (this returns me a vector) - I now want to find the x,y,z coordinates of each ele