[R] The correct way to set an element in a list to NULL? (FAQ is not clear)

Steve Lianoglou mailinglist.honeypot at gmail.com
Fri Dec 11 18:51:39 CET 2009


On Dec 11, 2009, at 12:36 PM, Peng Yu wrote:
[snip]

>>> What seems confusing to me is:
>>> even 'x[i]<-list(NULL)' and 'x[[i]]<-list(NULL)' are different, why
>>> x[i]<-NULL and x[[i]]<-NULL are the same?
>>> 
>>> Shouldn't the meaning of 'x[[i]]<-NULL' be defined as the set the i'th
>>> element NULL, rather than deleting the i'th element?
> 
> Do you have any comments on the above question?

Sure.

I think it has something to do with how memory is managed and allocated in R.  You might try to read up on it a bit ... 

In all seriousness tho:

No, I don't really have any comment on that question.

The semantics of what "x[i]<-list(NULL)" vs "x[[i]]<-list(NULL)" seems quite reasonable to me ... I'm not sure what that has to do with anything.

I also can't comment on why x[[i]] <- NULL deletes the element (instead of setting it to NULL, like you want it to) .. it's just the way it is.

That having been said. Once you "get it" (and I guess it's on the FAQ for a reason), then you can figure out how to deal with it.

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list