[R] list of lists, is this element empty

William Dunlap wdunlap at tibco.com
Sun Dec 21 21:39:19 CET 2014


Your 'x' has length 2, so x[[3]] cannot be calculated ('subscript out of
bounds' is what I get).  You can check for this with length(x)<3.

In general, you want to be more precise: 'does not have a value', 'is
NULL', and 'is empty' are not synonymous.  I'm not sure what 'does not have
a value' means to you.  NULL is a value with a certain type, 'NULL', and
length, 0.  seq_len(0) is empty, but not NULL, since it has type 'integer'.
 c(1,NA) contains a 'missing value'.  Can you explain what what you are
trying to check for, giving some context?



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Dec 20, 2014 at 7:58 AM, Ragia Ibrahim <ragia11 at hotmail.com> wrote:
>
> Hello,
> Kindly I have a list of lists as follow
> x
> [[1]]
> [1] 7
>
> [[2]]
> [1] 3 4 5
>
> as showen x[[3]] does not have a value and it has NULL, how can I check on
> this
> how to test if x[[3]] is empty.
>
> thanks in advance
> Ragia
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list