[BioC] [R] function to find coodinates in an array
Henrik Bengtsson
hb at stat.berkeley.edu
Fri Aug 17 04:52:21 CEST 2007
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,] 1 1 1
[2,] 2 1 1
[3,] 1 2 1
[4,] 2 2 1
[5,] 1 3 1
[6,] 2 3 1
[7,] 1 1 2
[8,] 2 1 2
[9,] 1 2 2
10,] 2 2 2
11,] 1 3 2
12,] 2 3 2
13,] 1 1 3
14,] 2 1 3
15,] 1 2 3
16,] 2 2 3
17,] 1 3 3
18,] 2 3 3
19,] 1 1 4
20,] 2 1 4
21,] 1 2 4
22,] 2 2 4
23,] 1 3 4
24,] 2 3 4
/Henrik
On 8/16/07, Moshe Olshansky <m_olshansky at yahoo.com> wrote:
> 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 Matlab).
>
> Regards,
>
> Moshe.
>
> --- Ana Conesa <aconesa at ochoa.fib.es> wrote:
>
> > 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
> > element of ord
> >
> > Can anyone help me?
> >
> > Thanks!
> >
> > Ana
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > 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.
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> 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.
>
More information about the Bioconductor
mailing list