arrays of lists in R ("cell arrays" in Matlab)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

arrays of lists in R ("cell arrays" in Matlab)

Giuseppe Pagnoni
Dear all

I would like to have some data in the form of a 2-dimensional array
(matrix) of lists, so that I can easily find the desired list object by
indexing the structure by rows and columns.  In matlab there exists a
data type called "cell array": a matrix of "cells", which are composite
objects very similar to R lists.

I know that in R you can create 1-dimensional arrays of lists, either
with the vector() function or by making a list of lists, but it is not
clear to me whether it is actually possible to have 2-dimensional arrays
of lists.

thank you very much for any suggestion

best

    giuseppe

--
-----
Giuseppe Pagnoni
Psychiatry and Behavioral Sciences
Emory University School of Medicine
101 Woodruff Circle, Suite 4000
Atlanta, GA, 30322
tel: 404.712.8431
fax: 404.727.3233

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: arrays of lists in R ("cell arrays" in Matlab)

Gabor Grothendieck
Try this:

L <- list(sqrt, letters, pi, 1:4)
dim(L) <- c(2,2)
L[[1,1]](4) # 2


On 2/15/06, Giuseppe Pagnoni <[hidden email]> wrote:

> Dear all
>
> I would like to have some data in the form of a 2-dimensional array
> (matrix) of lists, so that I can easily find the desired list object by
> indexing the structure by rows and columns.  In matlab there exists a
> data type called "cell array": a matrix of "cells", which are composite
> objects very similar to R lists.
>
> I know that in R you can create 1-dimensional arrays of lists, either
> with the vector() function or by making a list of lists, but it is not
> clear to me whether it is actually possible to have 2-dimensional arrays
> of lists.
>
> thank you very much for any suggestion
>
> best
>
>    giuseppe
>
> --
> -----
> Giuseppe Pagnoni
> Psychiatry and Behavioral Sciences
> Emory University School of Medicine
> 101 Woodruff Circle, Suite 4000
> Atlanta, GA, 30322
> tel: 404.712.8431
> fax: 404.727.3233
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: arrays of lists in R ("cell arrays" in Matlab)

Prof Brian Ripley
In reply to this post by Giuseppe Pagnoni
On Wed, 15 Feb 2006, Giuseppe Pagnoni wrote:

> I would like to have some data in the form of a 2-dimensional array
> (matrix) of lists, so that I can easily find the desired list object by
> indexing the structure by rows and columns.  In matlab there exists a
> data type called "cell array": a matrix of "cells", which are composite
> objects very similar to R lists.
>
> I know that in R you can create 1-dimensional arrays of lists, either
> with the vector() function or by making a list of lists, but it is not

Neither of those is the same thing as a 1D array, which does exist in R.
(Using 'array' in the C sense is going to lead to confusion.)

> clear to me whether it is actually possible to have 2-dimensional arrays
> of lists.

It is, and also 1D and 3D and 17D arrays of lists. You can create a matrix
list by assigning a dim() or by using matrix().

An array in R is just a vector with a dimension (and optionally dimnames),
and a list is a type of vector.

Such topics are covered in the more advanced books on the S/R language.

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html