Re: [R] assigning NULL to a list element without changing the length of the list

2012-11-15 Thread William Dunlap
tmp0 - list(a=1, b=2, c=3) tmp0[b] - list(NULL) # single [, list(NULL), not double [[ and bare NULL str(tmp0) # List of 3 # $ a: num 1 # $ b: NULL # $ c: num 3 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org

Re: [R] assigning NULL to a list element without changing the length of the list

2012-11-15 Thread arun
HI, You could try these: tmp1-list(a=1,b=NA,c=3,d=NA)  lapply(tmp1,function(x) if(is.na(x)) NULL else x)  #changing NA to NULL #$a #[1] 1 # #$b #NULL # #$c #[1] 3 # #$d #NULL #other case; tmp2-list(a=1,b=3,c=4,d=5)  #want to change list elements a, c to NULL tmp3-lapply(tmp2,function(x)

Re: [R] assigning NULL to a list element

2012-02-18 Thread Petr Savicky
On Sat, Feb 18, 2012 at 01:51:01AM +, 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

Re: [R] assigning NULL to a list element

2012-02-18 Thread Hadley Wickham
On Fri, Feb 17, 2012 at 7:51 PM, Benilton Carvalho beniltoncarva...@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,

Re: [R] assigning NULL to a list element

2012-02-18 Thread Benilton Carvalho
Thanks guys... I'm already embarrassed given how simple the solutions are. b On Saturday, 18 February 2012, Hadley Wickham wrote: On Fri, Feb 17, 2012 at 7:51 PM, Benilton Carvalho beniltoncarva...@gmail.com javascript:; wrote: Hi everyone, For reasons beyond the scope of this message,

Re: [R] assigning NULL to a list element

2012-02-17 Thread David Winsemius
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 __ R-help@r-project.org mailing list

Re: [R] assigning NULL to a list element

2012-02-17 Thread Benilton Carvalho
Thank you very much, David. __ 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.

Re: [R] assigning NULL to a list element

2012-02-17 Thread Mark Leeds
Hi Benilton: David's solution is short and sweet but below also works. I searched and searched and finally found it in the R-inferno by Patrick Burns. I never looked at the R-inferno carefully before. After glancing at it, I'm printing it out and binding it tomorrow. It's the got ya book for R.