[R] assigning NULL to a list element

Petr Savicky savicky at cs.cas.cz
Sat Feb 18 09:59:28 CET 2012


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 only

Hi.

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.



More information about the R-help mailing list