Skip to content
Prev 166012 / 398502 Next

How can pairs of values be stored in a 2D matrix ?

On Mon, Jan 5, 2009 at 6:30 AM, <mauede at alice.it> wrote:
I think the standard R way to do this would be with a 3-dimensional
array.  Many functions are designed to work well with n-dimensional
arrays, including apply and the plyr package.

But R does allow you to make a matrix of lists.
This creates a matrix of strings (character vector).  What you want is
a matrix of lists, something like this:

  A<-matrix(data=list(), nrow=2,ncol=4)

Then I think all your examples below work.

           -s

PS Note that it does *not* work to write data=NULL, because NULL is
not of class/mode 'list', even though the resulting matrix is filled
with NULL.