[R] array manipulation

Patrick Burns pburns at pburns.seanet.com
Thu Nov 3 10:35:32 CET 2011


You seem to be looking for 'aperm'.

There is a chapter in 'S Poetry' (available
on http://www.burns-stat.com) that talks
about working with higher dimensional
arrays.  I don't think any changes need
to be made for R.

On 02/11/2011 16:16, Simone Salvadei wrote:
> Hello,
> I'm at the very beginning of the learning process of this language.
> Sorry in advance for the (possible but plausible) stupidity of my question.
>
> I would like to find a way to permute the DIMENSIONS of an array.
> Something that sounds like the function "permute()" in matlab.
>
> Given an array C of dimensions c x d x T , for instance, the command
>
> permute(C, [2 1 3])
>
> would provide (in Matlab) an array very similar to C, but this time each
> one of the T matrices c x d has changed into its transposed.
> Any alternatives to the following (and primitive) 'for' cycle?
>
> *# (previously defined) phi=array with dimensions c(c,d,T)*
> *
> *
> *temp=array(0,dim=c(c,d,T))*
> * for(i in 1:T)*
> * {*
> * temp[,,i]=t(phi[,,i])*
> * }*
> * phi=temp*
> *
> *
>
> Thank you very much!
> S
>

-- 
Patrick Burns
pburns at pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')



More information about the R-help mailing list