ce
2017-Jun-15 16:06 UTC
[R] is.null(mylist[1]) and is.null(mylist$a) returns different values
Thank you all , very informative, never thought of doing a str( mylist[1] ) -----Original Message----- From: "Jeff Newmiller" [jdnewmil at dcn.davis.ca.us] Date: 06/15/2017 11:56 AM To: r-help at r-project.org, "Huzefa Khalil" <huzefa.khalil at umich.edu>, "ce" <zadig_1 at excite.com> Subject: Re: [R] is.null(mylist[1]) and is.null(mylist$a) returns different values I find that the str function is more helpful for understanding the difference between a null list and a list containing a null list than the implicit print function call that the interpreter invokes when you enter an expression at the console. str( mylist[1] ) -- Sent from my phone. Please excuse my brevity. On June 15, 2017 8:39:47 AM PDT, Huzefa Khalil <huzefa.khalil at umich.edu> wrote:>Hi, > >Try > >> is.null(mylist[[1]]) >[1] TRUE > >Notice the double square brackets. > >From: ?`[` >"The most important distinction between [, [[ and $ is that the [ can >select more than one element whereas the other two select a single >element." > >On Thu, Jun 15, 2017 at 11:33 AM, ce <zadig_1 at excite.com> wrote: >> Hi >> >> I have a list : >> >> mylist <- list( a = NULL, b = 1, c = 2 ) >> >>> mylist[1] >> $a >> NULL >> >>> is.null(mylist[1]) >> [1] FALSE >> >>> is.null(mylist$a) >> [1] TRUE >> >> why? I need to use mylist[1] >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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.