[R] alist()

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Nov 6 22:36:53 CET 2006


gah5 at comcast.net writes:

>  
> Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
> (regarding adding NULL elements to a list)
> 
> > > 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 $. 

Scalars are not equivalent to lists.

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list