[R] Anything like associative arrays in R?
Sean Davis
sdavis2 at mail.nih.gov
Wed Nov 2 14:36:15 CET 2005
On 11/2/05 8:24 AM, "kynn at panix.com" <kynn at panix.com> wrote:
>
>
>
>
> Let me preface my question by stressing that I am much less interested
> in the answer than in learning a way I could have *found the answer
> myself*. (As helpful as the participants in this list are, I have far
> too many R-related questions to resolve by posting here, and as I've
> written before, in my experience the R documentation has not been very
> helpful, but I remain hopeful that I may have managed to miss some
> crucial document.)
>
> The task I want to accomplish is very simple: to define and
> sequentially initialize M x N variables *programmatically*, according
> to two different categories, containing N and M values, respectively.
>
> In languages with associative arrays, the typical way to do this is to
> define a 2-d associative array; e.g. in Perl one could do
>
> for $i ( 'foo', 'bar', 'baz' ) {
>
> for $j ( 'eenie', 'meenie', 'minie', 'moe' ) {
>
> $table{ $i }{ $j } = read_table( "path/to/data/${i}_${j}.dat" );
> }
>
> }
>
> How does one do this in R? In particular, what's the equivalent of
> the above in R?
>
> Most importantly, how could I have found out this answer from the
> R docs?
I'm sure that you will get several answers about the specifics of how to do
this. As for where to look, in the "Introduction to R" manual, you will
find this section on lists:
http://cran.r-project.org/doc/manuals/R-intro.html#Lists-and-data-frames
It really helps to sit down with these documents and work your way through
them, as you have probably already started to do. Also, read the emails
from r-help for a while to learn what is possible to do with R.
Sean
More information about the R-help
mailing list