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

2012-11-15 Thread arun
p3<-lapply(tmp2,function(x) {if(names(tmp2)[match.call()[[2]][[3]]]%in% c("a","c")) NULL else x})  tmp3 #$a #NULL # #$b #[1] 3 # #$c #NULL # #$d #[1] 5 A.K. - Original Message - From: Gonçalo Ferraz To: r-help@r-project.org Cc: Sent: Thursday, November 15, 2

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

2012-11-15 Thread William Dunlap
-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Gonçalo Ferraz > Sent: Thursday, November 15, 2012 1:01 PM > To: r-help@r-project.org > Subject: [R] assigning NULL to a list element without changing the length of > the list > > Hi, > > I have

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

2012-11-15 Thread Gonçalo Ferraz
Hi, I have a list: tmp0 <- list(a=1, b=2, c=3) And I realize that I can append a NULL element to the end of this list, just by writing: length(tmp0) <- 4 Now, the question is, how can I assign NULL to one of the existing list elements without changing the length of the list? Please note I a

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 > > wrote: > > Hi everyone, > > > > For reasons beyond the scope of this message, I'd like to append a > > NULL el

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 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

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)) ##

Re: [R] assigning NULL to a list element

2012-02-17 Thread Benilton Carvalho
Hi Mark, thank you very much! This is perfect! Naive from my part not thinking of c()... Cheers, b __ 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

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.

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 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 https://stat.ethz.c

[R] assigning NULL to a list element

2012-02-17 Thread Benilton Carvalho
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 see