On Thu, Sep 3, 2009 at 5:50 AM, Peter Meilstrup
<peter.meilstrup@gmail.com>wrote:

> 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
>

This doesn't look like a list at all -- rather, it seems like a
3-dimensional array which has lists as its elements.

But it seems that the last dimension of your array is not actually used, so
can't you do just cbind(data1[,,1], data2[,,1]) ? Or if you really need that
empty dimension, use something like    array(cbind(data1,data2),
dim=c(3,2,1), dimnames=rownames(data1[,,1]))

(tried it with abind I just downloaded, and it says this: "Error in abind(x,
x2, along = 3, force.array = FALSE) :
  can only supply one list-valued argument for ...". Maybe it's a recent
change)


KK



> 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
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]


