[R] Named components in a list
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Thu Nov 10 23:48:35 CET 2011
Inline below ...
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
JulioSergio <juliosergio at gmail.com> wrote:
>Bert Gunter <gunter.berton <at> gene.com> writes:
>
>>
>> Inline Below.
>
>Well, Bert, then the manual where I found the example must be wrong. It
>is:
>
>http://cran.r-project.org/doc/manuals/R-intro.html#Constructing-and-modifying-
>lists
>
>And textually it says:
>
>Lists, like any subscripted object, can be extended by specifying
>additional
>components. For example
>
> > Lst[5] <- list(matrix=Mat)
It may be true that the example is susceptible to misinterpretation, but that is certainly what you are doing.
If there were four items in Lst, then after this statement there will be five, which means the list has been extended.
The item that has been added is an unnamed list. The arguments to any object creation function always describe the contents of that object, not the name by which you refer to the object.
If you wanted the next item in Lst to be a named list, you would refer to it by name when you assigned it:
Lst["mymatrix"] <- list (matrix=Mat)
But if you wanted to merge the elements of two lists you would concatenate:
Lst <- c(Lst, list(matrix = Mat))
More information about the R-help
mailing list