Re: [R] Transfer a 3-dimensional array to a matrix in R

2015-10-21 Thread Chunyu Dong
thank you very much! Both the two methods work well for my data. Best wishes, Chunyu At 2015-10-20 19:48:18, "William Dunlap" wrote: >Or use aperm() (array index permuation): > > array(aperm(x, c(2,1,3)), c(6,3)) > [,1] [,2] [,3] > [1,]17 13 > [2,]4 10 16 >

Re: [R] Transfer a 3-dimensional array to a matrix in R

2015-10-20 Thread Dénes Tóth
Hi, Bill was faster than me in suggesting aperm() instead of apply(), however, his solution is still suboptimal. Try to avoid array(), and set the dimensions directly if possible. fn1 <- function(x) { apply(x, 3, t) } fn2 <- function(x) { array(aperm(x, c(2, 1, 3)), c(prod(dim(

Re: [R] Transfer a 3-dimensional array to a matrix in R

2015-10-20 Thread William Dunlap
Or use aperm() (array index permuation): > array(aperm(x, c(2,1,3)), c(6,3)) [,1] [,2] [,3] [1,]17 13 [2,]4 10 16 [3,]28 14 [4,]5 11 17 [5,]39 15 [6,]6 12 18 Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Oct 20, 20

Re: [R] Transfer a 3-dimensional array to a matrix in R

2015-10-20 Thread John Laing
> x <- array(1:18, dim=c(3, 2, 3)) > x , , 1 [,1] [,2] [1,]14 [2,]25 [3,]36 , , 2 [,1] [,2] [1,]7 10 [2,]8 11 [3,]9 12 , , 3 [,1] [,2] [1,] 13 16 [2,] 14 17 [3,] 15 18 > apply(x, 3, t) [,1] [,2] [,3] [1,]17 13