[R] how to cut a multidimensional array along a chosen dimension and store each piece into a list

Hadley Wickham hadley at rice.edu
Tue Jan 18 00:07:55 CET 2011

On Mon, Jan 17, 2011 at 2:20 PM, Sean Zhang <seanecon at gmail.com> wrote:
> Dear R-Helpers,
> I wonder whether there is a function which cuts a multiple dimensional array
> along a chosen dimension and then store each piece (still an array of one
> dimension less) into a list.
> For example,
> arr <- array(seq(1*2*3*4),dim=c(1,2,3,4))  # I made a point to set the
> length of the first dimension be 1to test whether I worry about drop=F
> option.
> brkArrIntoListAlong <- function(arr,alongWhichDim){
> ####
> return(outlist)
> }
> I have tried splitter_a in plyr package but does not get what I want.
> library(plyr)
> plyr:::splitter_a(arr,3)

We'll you're really not supposed to call internal functions - you probably want:

alply(arr, 3)

but you don't say what is wrong with the output.


Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University

More information about the R-help mailing list