[R] abind, but on lists?

Peter Meilstrup peter.meilstrup at gmail.com
Thu Sep 3 04:50:11 CEST 2009


I'm trying to massage some data from Matlab into R. The matlab file  
has a "struct array" which when imported into R using the R.matlab  
package,  becomes an R list with 3+ dimensions, the first of which  
corresponds to the structure fields, with corresponding row names, and  
the second and third+ dimensions correspond to the dimensions of the  
original struct array (as matlab arrays always have 2+ dimensions).  
For example a 1x1 matlab struct array with three fields becomes:

 > data
, , 1

           [,1]
trials    List,1002
beforeRun List,8
afterRun  List,8

If I load two data files, I would want to concatenate them into a  
single list. cbind() doesn't preserve the row names, possibly because  
the array has three dimensions?

 > cbind(data1, data2)
      data1     data2
[1,] List,1002 List,479
[2,] List,8    List,8
[3,] List,8    List,8

Then I looked into abind(), which is even more puzzling: it preserves  
the names and dimensions correctly, but converts the entries into  
strings?!

 > abind(list(data1, data2), along=2, force.array=FALSE)
, , 1

           [,1]               [,2]
trials    "0"                "1"
beforeRun "2079647.50207592" "0"
afterRun  "1"                "0"

Is there a quick way to accomplish the effect I want? I want an output  
that looks like:

 > somebind(data1, data2, along=2)
, , 1

           [,1]               [,2]
trials    List,1002 List,479
beforeRun List,8    List,8
afterRun  List,8    List,8

Cheers,
Peter




More information about the R-help mailing list