[R] Transpose array
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Tue Feb 24 19:20:07 CET 2009
MarcioRibeiro wrote:
> Hi Listers,
> Is there a way that I can transpose an array...
> Suppose I have the following array...
>
> x<-array(c(1,2,3,4),dim=c(1,2,2))
> , , 1
> [,1] [,2]
> [1,] 1 2
> , , 2
> [,1] [,2]
> [1,] 3 4
>
> And I would like to get the following result...
> , , 1
> [,1]
> [1,] 1
> [,2] 2
> , , 2
> [,1] [,2]
> [1,] 3
> [,2] 4
>
> Thanks in advance,
> Marcio
I think you're looking for
aperm(x,c(2,1,3))
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list