[R] alist()
gah5 at comcast.net
gah5 at comcast.net
Tue Nov 7 00:07:23 CET 2006
Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
> > > > x["two"] <- list(NULL)
> > This seems to work.
> > In the actual case, it is assigning from a variable that may
> > or may not be null,
> > for example:
> > two<-NULL
> > x["two"]<-list(two)
> > It seems to work, and not do what it looks like, add a list of
> > length one. I suppose I should realize by now that scalars
> > are just like lists of length one, but this still wasn't obvious.
> Actually, it is a bit more subtle:
> The key point is that the left hand side of the assignment is a list.
> This is the difference between indexing with [] rather than [[]] or $.
Well, that and the list() on the right:
Yes, it is subtle. I tried it out with:
x<-list()
two<-2
x["two"]<-list(two)
typeof(x$two)
and it comes out "double", not "list"
Even more interesting:
x["two"]<-list(two,two)
Warning message:
number of items to replace is not a multiple of replacement length
Instead of a two element list in x["two"] like I might have thought.
x[["two"]]<-list(two,two)
does generate the list of list form, though.
thanks,
-- glen
More information about the R-help
mailing list