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

Rui Barradas ruipbarradas at sapo.pt
Thu Jun 15 17:38:30 CEST 2017


Hello,

You have to be aware that mylist[1] and mylist[[1]] are different things.


class(mylist[1])
[1] "list"
class(mylist[[1]])
[1] "NULL"


Apparently you want/need the latter:

is.null(mylist[[1]])
[1] TRUE


Hope this helps,

Rui Barradas

Em 15-06-2017 16:33, ce escreveu:
> 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.
>



More information about the R-help mailing list