Hi everyone, For reasons beyond the scope of this message, I'd like to append a NULL element to the end of a list. tmp0 <- list(a=1, b=NULL, c=3) append(tmp0, c(d=4)) ## works as expected append(tmp0, c(d=NULL)) ## list with a/b/c only Given that I could use tmp0$a <- NULL to remove 'a', I seem to understand why appending NULL returns me the original list... But how should I proceed to actually have d=NULL (just like I have 'b' in tmp0 above)? Thank you very much, benilton
On Feb 17, 2012, at 8:51 PM, Benilton Carvalho wrote:> tmp0 <- list(a=1, b=NULL, c=3)> length(tmp0) <- 4 > tmp0 $a [1] 1 $b NULL $c [1] 3 [[4]] NULL David Winsemius, MD West Hartford, CT
Thank you very much, David.
On Sat, Feb 18, 2012 at 01:51:01AM +0000, Benilton Carvalho wrote:> Hi everyone, > > For reasons beyond the scope of this message, I'd like to append a > NULL element to the end of a list. > > tmp0 <- list(a=1, b=NULL, c=3) > append(tmp0, c(d=4)) ## works as expected > append(tmp0, c(d=NULL)) ## list with a/b/c onlyHi. Besides the other solutions in this thread, the following also works. append(tmp0, list(d=NULL)) $a [1] 1 $b NULL $c [1] 3 $d NULL Petr Savicky.
On Fri, Feb 17, 2012 at 7:51 PM, Benilton Carvalho <beniltoncarvalho at gmail.com> wrote:> Hi everyone, > > For reasons beyond the scope of this message, I'd like to append a > NULL element to the end of a list. > > tmp0 <- list(a=1, b=NULL, c=3) > append(tmp0, c(d=4)) ## works as expected > append(tmp0, c(d=NULL)) ## list with a/b/c only > > Given that I could use > > tmp0$a <- NULL > > to remove 'a', I seem to understand why appending NULL returns me the > original list... But how should I proceed to actually have d=NULL > (just like I have 'b' in tmp0 above)?tmp0["d"] <- list(NULL) ? Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/