[R] How can pairs of values be stored in a 2D matrix ?
Stavros Macrakis
macrakis at alum.mit.edu
Mon Jan 5 18:02:39 CET 2009
On Mon, Jan 5, 2009 at 6:30 AM, <mauede at alice.it> wrote:
> My question is motivated by dealing with pairs of values, like (3,12.5), (16,2.98), and so on
> that are mapped to a cartesian plain (Time, Frequence)
> I miss C multidimensional arrays. I am trying to simulate the 3rd dimension by declaring a matrix of lists.
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.
>> A <- matrix(data ="list", nrow=2, ncol=4)
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.
More information about the R-help
mailing list