[R] is.null(mylist[1]) and is.null(mylist$a) returns different values

Huzefa Khalil huzefa.khalil at umich.edu
Thu Jun 15 17:39:47 CEST 2017


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.



-- 
Huzefa Khalil
PhD Candidate,
Department of Political Science,
University of Michigan



More information about the R-help mailing list