Skip to content
Back to formatted view

Raw Message

Message-ID: <49A43A57.8020301@biostat.ku.dk>
Date: 2009-02-24T18:20:07Z
From: Peter Dalgaard
Subject: Transpose array
In-Reply-To: <22184286.post@talk.nabble.com>

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