From: Evan Cooch <cooch17_at_verizon.net>

Date: Wed 27 Sep 2006 - 16:07:48 GMT

R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Thu Sep 28 02:15:07 2006

Date: Wed 27 Sep 2006 - 16:07:48 GMT

In the process of moving a number of my scripts from MATLAB -> R, I've
discovered that there is no 'pure' equivalent of MATLAB's cell arrays,
which I use quite often. Basically, I create matrices (as a cell array)
where each element of the matrix is itself a matrix (e.g., 2x2 cell
array where each element of the array is another matrix). I pass these
cell arrays to various functions which then do clever things with the
various matrices (of course) - basically, I need to be able to pass
collections of matrices to functions to do various things, and I need to
be able to control the dimensionality of the cell array to preserve some
structural relationships among the matrices in the array. The cell array
in MATLAB handles this with aplomb.

So far, in R, I've used lists. Given (say) 4 matrices (A,B,C,D), in MATLAB I can use

test={A,B,C,D} for a row vector cell array, or

test={A;B;C;D} for a column vector cell array.

In R, I get more or less the same thing using

The only way I can figure out how to do this in R is using something like

test=list(A,B,C,D);

dim(test) < c(2,2);

This seems to work, but defaults to bycolumn (in other words, instead of

A B

C D

I get

A C

B D

)

So, I follow with

test=t(test) as needed to flip the thing around to byrow.

OK, so the question is - is there a better way? This *seems* to work, but I'm discovering that R is a lot like working with LaTeX (something I know much more about) - you can do most things, but there is often a more elegant way if you can figure out how to find out about it.

Thanks in advance...

R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Thu Sep 28 02:15:07 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Wed 27 Sep 2006 - 17:30:22 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*