[R] Named components in a list

JulioSergio juliosergio at gmail.com
Thu Nov 10 23:58:56 CET 2011


Jeff Newmiller <jdnewmil <at> dcn.davis.ca.us> writes:

> 
> >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))
> 
> 

Yeah, all that you say is right, but my point is, then what is the use of 
puting this example in the manual (tutorial), because the same result could
be obtained by simply writing:

> Lst[5] <- Mat

istead of > Lst[5] <- list(matrix=Mat) ?



More information about the R-help mailing list