[R] how to reshape an array avoiding for loops

Berton Gunter gunter.berton at gene.com
Tue Aug 16 23:16:54 CEST 2005


?aperm

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of 
> Wladimir Eremeev
> Sent: Tuesday, August 16, 2005 2:12 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] how to reshape an array avoiding for loops
> 
> Dear r-help,
> 
>   I have an array a1 with dimensions [1:660,1:65,1:25]
>   I would like the first dimension to be the last one.
>   That is I want and array [1:65,1:25,1:660]
> 
>   The only way to do this, I know, is
>   
>   tmp.a<-array(dim=dim(a1)[c(2,3,1)])
>   for(i in 1:dim(a1)[1]) tmp.a[,,i]<-a1[i,,]
>   a1<-tmp.a
>   rm(tmp.a)
> 
>   
>   Is it possible to avoid 'for' loop here?
> 
>   Thank you!
> 
> ---
> Best regards,
> Wladimir                mailto:wl at eimb.ru
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list