Hi Kynn: this oddity  is discussed in Patrick Burn's document called "The R
   Inferno". I don't recall the fix so I'm not sure if below is the same as
   what his book says to do but it seems to do what you want.
   x <- list()
   x[[1]] <- 2
   x
   length(x)
   print(str(x))
   x[2] <- list(NULL)
   x
   length(x)
   print(str(x))
   Still,  I would look at that document rather than just using the above
   because I'm not an expeRt
   so there might be a better way ?
   Also, if you cant find Pat's website, let me know and  I'll find it. I'm
   pretty sure that,  if you
   google  "Patrick Burns", his site should be up at the top and then his
   R-Inferno is easy to
   find from there. It's quite a useful document so I highly recommend it.

   On May 22, 2009, Kynn Jones <kyn...@gmail.com> wrote:

     I'm an experienced programmer, but learning R is making me lose the little
     hair I have left...
     > list(NULL)
     [[1]]
     NULL
     > length(list(NULL))
     [1] 1
     > x <- list()
     > x[[1]] <- NULL
     > x
     list()
     > length(x)
     [1] 0
     >From the above experiment, it is clear that, although one can create a
     one-element list consisting of a NULL element, one can't get the same
     result
     by assigning NULL to the first element of an empty list. And it gets
     worse:
     > x <- list(1, 2, 3)
     > length(x)
     [1] 3
     > x[[2]] <- NULL
     > length(x)
     [1] 2
     I just could NOT believe my eyes! Am I going crazy???
     What I'm trying to do is so simple and straightforward: I want to be able
     to
     append NULL to a list, and, after the appending, have the last element of
     the list be NULL. Is that so unreasonable? How can it be done?
     TIA!
     Kynn
     [[alternative HTML version deleted]]
     ______________________________________________
     [1]r-h...@r-project.org mailing list
     [2]https://stat.ethz.ch/mailman/listinfo/r-help
     PLEASE do read the posting guide
     [3]http://www.R-project.org/posting-guide.html
     and provide commented, minimal, self-contained, reproducible code.

References

   1. mailto:R-help@r-project.org
   2. https://stat.ethz.ch/mailman/listinfo/r-help
   3. http://www.R-project.org/posting-guide.html
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to