Although I suggested to someone else that for-loops be avoided, they are not in 
the inner loop in this code, and it's probably easier to understand than some 
sort of apply:

a = array(round(100*runif(60)),dim=c(3,4,5))
a
for (i in 1:dim(a)[1])
 for (j in 1:dim(a)[2])
  a[i,j,] = sort(a[i,j,])
a

Is that what you want?

-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Maas James Dr (MED)
Sent: Friday, February 18, 2011 8:01 AM
To: r-help@r-project.org
Subject: [R] sort a 3 dimensional array across third dimension ?

I'm attempting to sort a 3 dimensional array that looks like this
> x
, , 1
     [,1] [,2]
[1,]    9    9
[2,]    7    9
, , 2
     [,1] [,2]
[1,]    6    5
[2,]    4    6
, , 3
     [,1] [,2]
[1,]    2    1
[2,]    3    2

Such that it ends up like this ....
> y
, , 1
     [,1] [,2]
[1,]    2    1
[2,]    3    2
, , 2
     [,1] [,2]
[1,]    6    5
[2,]    4    6
, , 3
     [,1] [,2]
[1,]    9    9
[2,]    7    9

I think this is sorting across the third dimension but several attempts using 
either the sort or apply functions have not worked.  Any and all suggestions 
most welcome.  Thanks

J

===============================
Dr. Jim Maas
University of East Anglia


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.




message may contain confidential information. If you are not the designated 
recipient, please notify the sender immediately, and delete the original and 
any copies. Any use of the message by you is prohibited. 
______________________________________________
R-help@r-project.org 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.

Reply via email to