Re: [R] Rotate array by 90°

2015-02-11 Thread Karim Mezhoud
Thanks Lee and Huang. That is useful. Best On Fri, Feb 6, 2015 at 1:53 AM, Chel Hee Lee wrote: > > lapply(1:2, function(x) t(A[rev(1:3),,x])) > [[1]] > [,1] [,2] [,3] > [1,] "g" "d" "a" > [2,] "h" "e" "b" > [3,] "i" "f" "c" > > [[2]] > [,1] [,2] [,3] > [1,] "p" "m" "j" > [2,

Re: [R] Rotate array by 90°

2015-02-05 Thread Chel Hee Lee
> lapply(1:2, function(x) t(A[rev(1:3),,x])) [[1]] [,1] [,2] [,3] [1,] "g" "d" "a" [2,] "h" "e" "b" [3,] "i" "f" "c" [[2]] [,1] [,2] [,3] [1,] "p" "m" "j" [2,] "q" "n" "k" [3,] "r" "o" "l" > Is this what you are looking for? I hope this helps. Chel Hee Lee On 02/05/2015

Re: [R] Rotate array by 90°

2015-02-05 Thread JS Huang
Hi, Here is an implementation. > rot90 function(a,times=1) { row <- dim(a)[1] col <- dim(a)[2] dep <- dim(a)[3] if (times %% 2 == 1){t <- row; row <- col; col <- t} tempA <- array(NA, c(row,col,dep)) for (i in 1:dep) { temp <- a[,,i] for (j in 1:times) { temp <-

Re: [R] Rotate array by 90°

2015-02-05 Thread Karim Mezhoud
Thanks Jeff and Rui. On Thu, Feb 5, 2015 at 11:12 PM, Rui Barradas wrote: > Hello, > > Try the following. > > > rot90 <- function(x, n = 1){ > r90 <- function(x){ > y <- matrix(rep(NA, prod(dim(x))), nrow = nrow(x)) > for(i in seq_len(nrow(x))) y[, i] <

Re: [R] Rotate array by 90°

2015-02-05 Thread Rui Barradas
Hello, Try the following. rot90 <- function(x, n = 1){ r90 <- function(x){ y <- matrix(rep(NA, prod(dim(x))), nrow = nrow(x)) for(i in seq_len(nrow(x))) y[, i] <- rev(x[i, ]) y } for(i in seq_len(n)) x <- r90(x) x }

Re: [R] Rotate array by 90°

2015-02-05 Thread Jeff Newmiller
?aperm aperm(A, c(2,1,3) )[,3:1,] --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#

[R] Rotate array by 90°

2015-02-05 Thread Karim Mezhoud
Dear aal, Is there a way to rotate array or a cube of matrices by Y axis? MatLab example: A = cat(3,{'a' 'b' 'c';'d' 'e' 'f';'g' 'h' 'i'},{'j' 'k' 'l';'m' 'n' 'o';'p' 'q' 'r'}) A(:,:,1) = 'a''b''c' 'd''e''f' 'g''h''i' A(:,:,2) = 'j''k''l'